c# - Is this the intended behavior of textbox and label? -
I set the value of the control when the DOM loads. I have this super simple code on the ASPX page:
& lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ('# & lt;% = textbox2.ClientID% & gt;') Val ($ ('# & lt;% = textbox1.clientID% & gt;') Val (); $ ('# & lt;% = lblVal.ClientID% & gt;') .HTML ($ ('# & lt;% = textbox1.ClientID% & gt;') Val ()) ;}); & Lt; / Script & gt; & Lt; ASP: Text Box Runat = "Server" id = "Text Box 1" Text = "Test Data" /> & Lt; ASP: Text Box Runat = "Server" id = "Text Box 2" /> & Lt; Asp: label runat = "server" id = "lblVal" text = "old data" /> & Lt; ASP: Button Runat = "server" text = "click me" onclick = "anonymous1" link "" & gt; Click on my button in the event handler I have this code:
Secure Zero Anonymous 1_Cick (Object Sender, EventArgs e) {Debug.Write ( TextBox2.Text); Debug.Write (lblVal.Text); } This thing which was shocking to me, is the old price of LLBL. Setting a value in JavaScript does not really have any effect on the label, while textbox2's data appears on the server. Is textbox and label intention intensive? This is surprising for me because I have never come to this point before.
label on an HTML label tag, not a form field. Therefore, there is no value in the form, which is posted, and the values that you restore in postback are from Vostast. The form field (such as the ASP text box, which becomes a input ) will post its value and it will override the value in the viewstate. You have a secret input around it that you update with Javascript, and then update the label's content in your postback instead.
Comments
Post a Comment