收藏起来。
1、不设置readonly,设置onfocus=this.blur()
c#代码
<asp:textbox id="textbox1" runat="server" onfocus=this.blur()></asp:textbox>
<asp:textbox id="textbox1" runat="server" onfocus=this.blur()></asp:textbox>
文本框不变灰色,但也无法手动修改内容,可以在后台通过text属性正常赋值取值
2、设置了readonly属性后,通过request来取值,如下:
前台代码:
<asp:textbox id="textbox1" runat="server" readonly="true" ></asp:textbox>
<asp:textbox id="textbox1" runat="server" readonly="true" ></asp:textbox>
后台代码:
string text = request.form[textbox1].trim();
string text = request.form[textbox1].trim();
3、在page_load()正设置文本框的只读属性,能正常读取,如下:
c#代码
protected void page_load(object sender, eventargs e)
{
if (!page.ispostback)
{
textbox1.attributes.add(readonly,true);
}
}