简体   繁体   中英

javascript to asp.net ClientIDMode

I'm new and learning asp.net and javascript.

It could be silly question, because I would like to check how to work on asp.net with javascript.

The button calls OnClientClick for client side only and I want that the javascipt changes the label on asp.net. When it press the button, it seems be changed, but it will turn back to original label.

Is there way to make static the label value from javascript?

Thanks in advance.

 <script type="text/javascript"> function calledFn() { document.getElementById('<%=Label1.ClientID%>').innerHTML = document.getElementById('<%=TextBox1.ClientID%>').value; document.getElementById('<%=Label2.ClientID%>').innerHTML = document.getElementById('<%=TextBox2.ClientID%>').value; document.getElementById('<%=Label3.ClientID%>').innerHTML = document.getElementById('<%=TextBox3.ClientID%>').value; document.getElementById('<%=Label4.ClientID%>').innerHTML = document.getElementById('<%=TextBox4.ClientID%>').value; } </script> 

 <body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <br /><br /> <asp:Button ID="Button1" runat="server" Text="Run JavaScript Code" OnClientClick="calledFn()"/> <br /><br /> <asp:Label ClientIDMode="Static" ID="Label1" runat="server">t111</asp:Label> <asp:Label ClientIDMode="Static" ID="Label2" runat="server">t222</asp:Label> <asp:Label ClientIDMode="Static" ID="Label3" runat="server">t333</asp:Label> <asp:Label ClientIDMode="Static" ID="Label4" runat="server">t444</asp:Label> </form> </body> 

Your javascript changes will not be saved.

You have to use session,view state, or hidden fields to temporarily store changes then rebind them on pageload

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM