使用javascript设置asp.net文本框值 [英] Set asp.net textbox value using javascript
问题描述
我想使用javascript设置asp.net文本框的值
我的JS代码是:
document.getElementById('<%= txtFlag.ClientID%>')。value =Track;
我的文本框是:
< asp:TextBox ID =txtFlagrunat =serverVisible =False>< / asp:TextBox>
但是它给了我一个错误 document.getElementById(...)'是null还是不是对象
我不明白什么是错的。
请帮助。
解决方案1:
将该文本框设为visible = true并尝试,
当您将控件设置为可见false时,该控件将不会在客户端加载,因为您知道javascript将在客户端执行问题2:
在页面末尾添加此javascript。
I want to set the value of a asp.net textbox using javascript
My JS Code is:
document.getElementById('<%=txtFlag.ClientID %>').value = "Track";
My textbox is:
<asp:TextBox ID="txtFlag" runat="server" Visible="False"></asp:TextBox>
But it gives me an error document.getElementById(...)' is null or not an object
I dont understand what is wrong.
Please help.
Solution 1:
Make that textbox as visible=true and try,
When you make a control as visible false, that control will not be loaded in client side and as you knew javascript will be executed on client side itself.
Solution 2:
Add this javascript at the end of the page.
这篇关于使用javascript设置asp.net文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!