ASP .NET readonly texbox 后台不能读取问题的解决办法
2010-10-09 21:44
691 查看
最近在做一些ASP .NET和silverlight的项目,把遇到的一些问题记在这里吧:)
如果需要有一个textbox只能接受特定格式的东西,一个做法是把这个textbox做成readonly的,然后通过别的方式,比如javascript动态的生成需要填充的东西,放进这个textbox里面。但是在ASP的程序中postback到后台后会发现拿不到这个textbox的值,原因在msdn里做了如下解释。
The Text value of a TextBox control with the ReadOnly property set to true
is sent to the server when a postback occurs, but the server does no
processing for a read-only text box. This prevents a malicious user from
changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code.
TextBox.ReadOnly Property (System.Web.UI.WebControls)
一个简单的解决办法是,在code behand中设置read only 属性,示例代码如下:
textboxReadonly.Attributes.Add("readonly", "readonly");
这样的话就可以了。
如果需要有一个textbox只能接受特定格式的东西,一个做法是把这个textbox做成readonly的,然后通过别的方式,比如javascript动态的生成需要填充的东西,放进这个textbox里面。但是在ASP的程序中postback到后台后会发现拿不到这个textbox的值,原因在msdn里做了如下解释。
The Text value of a TextBox control with the ReadOnly property set to true
is sent to the server when a postback occurs, but the server does no
processing for a read-only text box. This prevents a malicious user from
changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code.
TextBox.ReadOnly Property (System.Web.UI.WebControls)
一个简单的解决办法是,在code behand中设置read only 属性,示例代码如下:
textboxReadonly.Attributes.Add("readonly", "readonly");
这样的话就可以了。
相关文章推荐
- ASP.Net生成后台脚本的问题的解决办法
- ASP/ASP.NET不能调试问题的解决办法
- ASP.Net生成后台脚本的问题的解决办法
- 一些ASP.NET不能调试问题的解决办法!
- ASP.NET中应用UltraWebGrid控件时在Cell中按一下回车后不能自动转到下一单元格的问题及解决办法
- ASP.Net生成后台脚本的问题的解决办法
- 在iis7下部署ASP.NET程序AjaxPro不能用问题解决办法
- 一些ASP.NET不能调试问题的解决办法!
- asp.net TextBox只读时不能通过后台赋值取值解决办法
- ASP.Net生成后台脚本的问题的解决办法
- 在iis8.5下部署ASP.NET程序AjaxPro不能用问题解决办法
- Asp.net 从Excel读取图片并保存,无法从内存读取图片,Excel组件和相关IIS的配置及解决办法
- iis之asp.net环境配置问题及解决办法
- "Failed to update database "c:\inetpub\wwwroot\WebSite1\App_Data\ASPNETDB.MDF" because the database is read-only."的解决办法
- 解决ASP.NET不能调试的问题。
- 【ASP.NET 问题】IIS发布网站后出现“检测到在集成的托管管道模式下不适用的ASP.NET设置”的解决办法
- java jsoup 爬虫爬asp.net网站遇到_doPostBack不能获取翻页数据解决办法
- Infragistics NetAdvantage 的 ASP.NET部分控件在IE7.0 IE8.0 下不能正常工作的问题及解决
- ASP.NET Post页面及验证视图状态MAC失败问题的正确解决办法
- 在VS2003+IE7.0下调试asp.net权限问题的解决办法