c# - Using onChange Event in ASP.NET combined with Bootstrap -
i wanna create 2 textareas. first textarea should used user. every time user change textarea value should checked , given out in textarea. tried add runat="server"
, onchange="ftextchanged"
in bootrstrap textarea control. usercontrol:
<div class="row"> <div class="form-group"> <label for="totranslate">text translate:</label> <textarea class="form-control" runat="server" onchange="ftextchanged" rows="5" id="totranslate"></textarea> </div> </div> <div class="row"> <div class="form-group"> <label for="translatedtext">translated text:</label> <textarea class="form-control" runat="server" rows="5" id="translatedtext"></textarea> </div> </div>
and codebehind:
public void ftextchanged(object sender, eventargs e) { string content = totranslate.value; translatedtext.value = content; }
i tried debug it, appears compiler(website?) ignore function. vs2017 dont stop @ breakpoint:
content = totranslate.value;
i'm new in web programming @ all, i'm used c#, c++, , labview. hope nice guys can me.
kind regards!
edit:
changing:
<textarea class="form-control" runat="server" onchange="ftextchanged" rows="5" id="totranslate"></textarea>
to:
<asp:textbox class="form-control" id="totranslate" runat="server" ontextchanged="ftextchanged" autopostback="true" textmode="multiline" rows="5"></asp:textbox>
worked pretty well.
if want on client side use onchange
event javascript code follows
function keyup() { var totranslate = document.getelementbyid("totranslate"); var s = totranslate.value; var translatedtext = document.getelementbyid("translatedtext"); translatedtext.innertext = ""+s; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="form-group"> <label for="totranslate">text translate:</label> <textarea class="form-control" runat="server" rows="5" id="totranslate" onkeypress="keyup()" onkeyup="keyup()"></textarea> </div> </div> <div class="row"> <div class="form-group"> <label for="translatedtext">translated text:</label> <textarea class="form-control" runat="server" rows="5" id="translatedtext"></textarea> </div> </div>
if should use server-side code however, transform html control asp.net control follows find server-side events on asp.net controls (not sure, check it);
<asp:textbox id="totranslate" runat="server" ontextchanged="ftextchanged" autopostback="true" clientidmode="static" textmode="multiline" rows="5"></asp:textbox>
Comments
Post a Comment