When I evaluate asp.net control events, I am not able to identify how the browser is aware of asp.net textbox is subscribed to serverside textchanged event or not. When I look the server generated HTML code, there is not information about the TextChanged event.

ASP.Net Declaration

<asp:TextBox ID="txtInput" runat="server" OnTextChanged="txtInput_OnTextChanged"
    AutoPostBack="false" />

Server Generated HTML Code

<input name="ctl00$MainContent$txtInput" type="text" value="SivaText Input ChangedText Input Changed.V ChangedText Input Changed.V Changed" id="MainContent_txtInput">

The server encodes the state of all input elements in the hidden field named __VIEWSTATE. Have a look at the rendered HTML and you can see it in the <div class="aspNetHidden"> element somewhere on the top.

When the form is submitted, both values from the HTML input form elements and the value in the hidden input element __VIEWSTATE are submitted together. For each input element the server compares the values submitted via the corresponding form element (e.g. <input type="text"> with the value encoded in the view state. If they are different, a TextChanged event is triggered for the server-side TextBox control.

| improve this answer | |

ASP.NET generates javascript that attaches to the onchange event causing a postback.

Part of the data sent in the postback/viewdata/viewstate includes what caused the postback with a translation from the client side event to the server side event.

Don't forget - ASP.NET renders normal HTML - on the browser it is just a <textarea> or <input type="text">, after all.

| improve this answer | |
  • Can we able to see server generated javascript codes?. Since, when I view the server generated hmtl file I am not able to see the javascript codes. – user46506 Jul 11 '14 at 12:11
  • Use the developer tools of the browser. Of course you can see the JS, given that the browser needs to see it. – Oded Jul 11 '14 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.