今天遇到一个问题,TextBox1 的Enabled=false或Readonly=true之后,通过JS的document.getElementById("TextBox1 ").innerText ="aaaa",这个值可以在TextBox1中显示但不能正确读出来
解决办法:
1、
Page_Load:
TextBox1.Style.Add("display","none");
2、把TextBox1丢到一个panel中,设置该panel的visible=false,但TextBox1的visible必须为true,否则JS中无法找到它
3、Server端的类似客户端的<INPUT type="hidden">隐藏控件
aspx页面中
<input type="hidden" id="hidden1" name="hidden1" runat="server>
服务端定义
protected System.Web.UI.HtmlControls.HtmlInputHidden hidden1;
在服务端用
string ss = hidden1.Value;
就可以直接取得它的值
hidden1.Value = "hello";
给它赋值