解决
办法:
不直接在页面
中设置而改为在代码中设置。
1、把textbox控件中的readonly=true去掉;
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>
文本框不变灰色,但也无法手动
修改
内容
,可以在后台通过Text属性正常赋值取值
2、设置了ReadOnly属性后,通过Request来取值,如下:
前台代码:
-
<asp:TextBox ID=
"TextBox1"
runat=
"server"
ReadOnly=
"True"
></asp:TextBox>
后台代码:
-
strin
g
Text = Request.Form[
"TextBox1"
].Trim();
3、在Page_Load()正设置文本框的只读属性,能正常读取,如下:
-
protected
void
Page_Load(
object
sender, EventArgs e)
-
{
-
if
(!Page.IsPostBack)
-
{
-
TextBox1.Attributes.Add("readonly"
,
"true"
);
-
}
-
}
分享到:
相关推荐
-修正TreeNode的属性NavigateUrl不接受服务器端URL(以~/开头)的BUG。 -增加Accordion和Tree配合使用的示例(other\accordion_tree_run.aspx)。 -修正Panel图标不能显示的BUG(CSS中class名不能有$字符)。 +去除...
-修正TreeNode的属性NavigateUrl不接受服务器端URL(以~/开头)的BUG。 -增加Accordion和Tree配合使用的示例(other\accordion_tree_run.aspx)。 -修正Panel图标不能显示的BUG(CSS中class名不能有$字符)。 +去除...
4.2 给服务器控件应用样式87 4.2.1 控件的常见属性87 4.2.2 使用层叠样式表 改变样式88 4.3 HTML服务器控件93 4.3.1 HtmlControl基类95 4.3.2 HtmlContainerControl类96 4.3.3 所有的HTML类96 4.3.4 使用...
7.2 客户端和服务器端的验证 194 7.3 ASP.NET验证服务器控件 195 7.3.1 验证原因 196 7.3.2 RequiredFieldValidator服务器控件 196 7.3.3 CompareValidator服务器控件 201 7.3.4 RangeValidator服务器控件 204 ...
Server Side ViewState 在服务器端存贮ViewState (ASP.NET 2.0) VS2005 ASP.NET本地化学习笔记&感受 在自定义Server Control中捆绑JS文件 Step by Step 深度解析Asp.Net2.0中的Callback机制 使用 Web 标准生成 ASP...
IValueConverter - 值转换接口,将一个类型的值转换为另一个类型的值。它提供了一种将自定义逻辑应用于绑定的方式 BindingValidationError - 出现验证错误或解决上次验证错误则触发此事件 14、Silverlight(16) - 2.0...