i'm having trouble while devolping .net application.
i'm using event ontextchanged on textbox change content in textbox, first textbox has autopostback="true", when write in , click in part, page refreshes completely.
here ascx code:
<form id="form1" runat="server"> change text <asp:textbox id="txt1" runat="server" ontextchanged="ejemplo" autopostback="true"/> <p><asp:label id="lbl1" runat="server" /></p> </form>
and script in same ascx page:
<script runat="server"> protected void ejemplo(object sender, eventargs e) { lbl1.text = "changed"; } </script>
i'm using mvc4, answers.
edit:
here video of happening: http://remainedesign.com/video/asd.html
life cycle of mvc , webforms both different. mvc not server controls.... viewstate... no page life cycle events in web form...
what 'page lifecycle' of asp.net mvc page, compared asp.net webforms? hope helps..
now coming point.
if want display in textbox2 while entering value textbox1 have use client side script, see example below
javascript
<script type="text/javascript" language="javascript"> function textcounter(field, field2, maxlimit) { var countfield = document.getelementbyid(field2); if (field.value.length > maxlimit) { field.value = field.value.substring(0, maxlimit); return false; } else { countfield.value = maxlimit - field.value.length; } } </script>
your html page
<%using (html.beginform("index", "account", formmethod.post)) // here index actionname, account controller name {%> <input type="text" id="textbox1" name="message" onkeyup="textcounter(this,'textbox2',208)"/> <input disabled maxlength="3" size="3" value="208" id="textbox2" /></label> <input type="submit" value="send" /> <%}%>
here
textcounter() function on keyup event in textbox1 display value in textbox2,
submit button submit form call action "index" on controller "account",see below how action act
public class accountcontroller : controller { [httppost] public actionresult index(formcollection result) { string textboxvalue=result["message"]; return view("yourviewname"); } }
please note,above example solely mvc project
i hope example may you..
Comments
Post a Comment