ASP.Net TextBox只读时不能通过后台赋值取值
2016-11-24 11:27
387 查看
今天在开发一个asp.net的页面遇到了TextBox设置了ReadOnly属性,在js中赋值后,后台代码取不到值的情况,经过在网上查找,找到了一下几个处理办法。
收藏起来。
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");
}
}
收藏起来。
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");
}
}
相关文章推荐
- ASP.Net TextBox只读时不能通过后台赋值取值
- ASP.Net TextBox只读时不能通过后台赋值取值
- ASP.Net TextBox只读时不能通过后台赋值取值
- ASP.Net TextBox只读时不能通过后台赋值取值
- ASP.Net TextBox只读时不能通过后台赋值取值
- asp.net TextBox只读时不能通过后台赋值取值解决办法
- ASP.Net TextBox只读时不能通过后台赋值取值
- ASP.Net TextBox只读时不能通过后台赋值取值
- ASP.Net TextBox 只读(ReadOnly)时后台不能赋值取值
- TextBox只读时不能通过后台赋值取值解决办法
- asp.net textbox只读时不能通过javascript赋值、采值解决办法
- ASP.Net TextBox只读时不能取值的解决方案
- ASP.NET中TextBox设置只读时不能取值的处理
- ASP.Net TextBox只读时不能取值的解决方案
- ASP.Net TextBox只读时不能取值
- asp.net 中TextBox只读时在客户端赋值后的取值问题
- asp.net通过js给TextBox赋值
- Javascript给隐藏控件赋值之后,ASP.NET不能正确取值问题总结
- asp.net中TextBox设为只读后的取值问题
- asp.net中TextBox设为只读后的取值问题