`
boss5518831534
  • 浏览: 228346 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

服务器端控件TextBox 设为只读属性后无法获取javascript给其赋的值

    博客分类:
  • .NET
阅读更多

 

解决 办法:

不直接在页面 中设置而改为在代码中设置。

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() 

C#代码 
  1. <asp :TextBox ID= "TextBox1"  runat= "server"  onfocus= this .blur()></asp:TextBox>  



文本框不变灰色,但也无法手动 修改 内容 ,可以在后台通过Text属性正常赋值取值 

2、设置了ReadOnly属性后,通过Request来取值,如下: 

前台代码: 

C#代码 
  1. <asp:TextBox ID= "TextBox1"  runat= "server"  ReadOnly= "True"  ></asp:TextBox>  



后台代码: 

C#代码 
  1. strin g  Text = Request.Form[ "TextBox1" ].Trim();  



3、在Page_Load()正设置文本框的只读属性,能正常读取,如下: 

C#代码 
  1. protected   void  Page_Load( object  sender, EventArgs e)  
  2. {  
  3.     if  (!Page.IsPostBack)  
  4.     {  
  5.         TextBox1.Attributes.Add("readonly" , "true" );  
  6.     }  
  7. }                               
分享到:
评论

相关推荐

    ExtAspNet_v2.3.2_dll

    -修正TreeNode的属性NavigateUrl不接受服务器端URL(以~/开头)的BUG。 -增加Accordion和Tree配合使用的示例(other\accordion_tree_run.aspx)。 -修正Panel图标不能显示的BUG(CSS中class名不能有$字符)。 +去除...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -修正TreeNode的属性NavigateUrl不接受服务器端URL(以~/开头)的BUG。 -增加Accordion和Tree配合使用的示例(other\accordion_tree_run.aspx)。 -修正Panel图标不能显示的BUG(CSS中class名不能有$字符)。 +去除...

    ASP.NET2.0高级编程(第4版)1/6

    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 使用...

    2.ASP.NET.2.0.高级编程(第4版) [1/7]

    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 ...

    asp.net知识库

    Server Side ViewState 在服务器端存贮ViewState (ASP.NET 2.0) VS2005 ASP.NET本地化学习笔记&感受 在自定义Server Control中捆绑JS文件 Step by Step 深度解析Asp.Net2.0中的Callback机制 使用 Web 标准生成 ASP...

    Silverlight2.0功能展示Demo源码

    IValueConverter - 值转换接口,将一个类型的值转换为另一个类型的值。它提供了一种将自定义逻辑应用于绑定的方式 BindingValidationError - 出现验证错误或解决上次验证错误则触发此事件 14、Silverlight(16) - 2.0...

Global site tag (gtag.js) - Google Analytics