<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="../js/jquery/jquery-1.4.1.min.js" type="text/javascript"></script> <script> function btnSetText_OnClientClick() { $("#<%= lbl1.ClientID %>").text("123"); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lbl1" runat="server"></asp:Label> <asp:Button ID="btnSetText" runat="server" Text="Set Text" OnClientClick="btnSetText_OnClientClick(); return false;" /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /> </div> </form> </body> </html> protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { string str1 = lbl1.Text; }
The script is here, when the user clicks βset textβ, the jquery script will update the label value, when the βSubmitβ button is pressed, the value of lbl1.Text is always ββ, which is lost after the postback, any ideas?
source share