简体   繁体   English

javascript到asp.net ClientIDMode

[英]javascript to asp.net ClientIDMode

I'm new and learning asp.net and javascript. 我是新手,正在学习asp.net和javascript。

It could be silly question, because I would like to check how to work on asp.net with javascript. 这可能是一个愚蠢的问题,因为我想检查如何使用javascript在asp.net上工作。

The button calls OnClientClick for client side only and I want that the javascipt changes the label on asp.net. 该按钮仅在客户端调用OnClientClick,我希望javascipt更改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? 有没有办法从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. 您的javascript更改将不会保存。

You have to use session,view state, or hidden fields to temporarily store changes then rebind them on pageload 您必须使用会话,视图状态或隐藏字段来临时存储更改,然后在页面加载时将其重新绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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