asp.net中的服务器端控件 textbox 设为只读属性后无法获取JS给其赋的值解决办法
来源:互联网 发布:弗欧炒锅怎样知乎 编辑:程序博客网 时间:2024/05/22 09:56
在TextBox控件中,发下修改文本内容后,提交更改时
无法将修改后的内容提交给服务器。也就是服务器端TextBox.Text获取的还是原来的内容。查了好半天终于清楚了,原来Asp.net
2.0以后限制了修改值回传的做法。不过这只是限制的Text属性,没有限制提交数据的名称/值的NameValueCollection,通过
Request["表单名称"]的方法仍然可以得到控件修改后的值,即可以使用Request.Form[TextBox1.UniqueID]来取得TextBox中
修改后的内容。
解决办法:
不直接在页面中设置而改为在代码中设置。
1、把textbox控件中的readonly=true去掉;
2、在后台代码Page_Load中添加属性: this.txtfilename.Attributes.Add("readonly", "true");
this.txtfilename.Attributes.Add("contenteditable", "false");
其中txtfilename为文本框控件的名。
给页面的TextBox设置ReadOnly="True"时,在后台代码中不能赋值取值,下边几种方法可以避免:
1、不设置ReadOnly,设置onfocus=this.blur()
<asp:TextBox ID="TextBox1" runat="server" onfocus=this.blur()></asp:TextBox>
2\设置了ReadOnly属性后,通过Request来取值,如下:
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" ></asp:TextBox>
string Text = Request.Form["TextBox1"].Trim();
3、在Page_Load()正设置文本框的只读属性,能正常读取,如下:
protected void Page_Load(object sender, EventArgs e)
{ if (!Page.IsPostBack)
{
TextBox1.Attributes.Add("readonly","true");
}
}
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取JS给其赋的值解决办法
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值
- js无法获取只读属性服务器端控件TextBox的值
- asp.net中TextBox设为只读后的取值问题
- asp.net中TextBox设为只读后的取值问题
- asp.net TextBox 设置为只读后 后台取不到JS设置的值
- js 获取 asp.net 服务器端控件 Label 与 TextBox RadioButtonList 与 DropDownList 的值
- js 获取 asp.net 服务器端控件 Label 与 TextBox RadioButtonList 与 DropDownList 的值
- js 获取 asp.net 服务器端控件 Label 与 TextBox RadioButtonList 与 DropDownList 的值
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
- js 获取 asp.net 服务器端控件 Label 与 TextBox RadioButtonList 与 DropDownList 的值
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropD
- TextBox属性设为Readonly时,.net后端程序无法取值的问题解决
- ASP.NET中TextBox控件ReadOnly属性设置为True,后台取值为空解决办法
- asp.net中将js的返回值赋给asp.net控件
- textBox的Enable属性设为false后,如何保持其字体的颜色 (Winform)
- asp.net中asp:TextBox的只读属性
- POJ 3414 Pots【bfs模拟倒水问题】
- HDU1259--ZJUTACM HDU(99)
- 心情随笔
- MTK6577修改成四核
- C++ 对象的内存布局(上)
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取JS给其赋的值解决办法
- SpringMVC
- Struts2 学习笔记15 Struts标签 part1
- 你猜对了么?一个函数考察Go 语言闭包、defer的用法
- IIS相关服务
- poj 1090 chain
- Linux 引导过程内幕
- eclipse配置Tomcat7
- [FAQ04549]JB Launcher2 代码导入Eclipse编译模拟器