惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
F
Fortinet All Blogs
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
爱范儿
爱范儿
博客园_首页
S
Security @ Cisco Blogs
H
Heimdal Security Blog
Cyberwarzone
Cyberwarzone
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
T
Threatpost
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
S
Security Affairs
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
博客园 - 聂微东
P
Privacy & Cybersecurity Law Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
NISL@THU
NISL@THU
G
GRAHAM CLULEY
人人都是产品经理
人人都是产品经理
L
LangChain Blog
The Register - Security
The Register - Security
L
LINUX DO - 最新话题
博客园 - 【当耐特】
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
IT之家
IT之家
云风的 BLOG
云风的 BLOG
量子位
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
腾讯CDC
大猫的无限游戏
大猫的无限游戏
美团技术团队
N
News | PayPal Newsroom
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Docker
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Cloudbric
Cloudbric

博客园 - 独孤雁

在win2008中安装vs2005 【转】NPOI 单元格级别应用 [转]google hosts 2015 [转] C#反射设置属性值和获取属性值 [转]Visual Studio技巧之打造拥有自己标识的代码模板 【转】mysql如何跟踪执行的sql语句 [转]VS2005/2008过期之后简单实用的升级方法 【转】在web 项目使用了ReportViewer时出错 使用NPOI导出excel window.location 对象所包含的属性 【原】提交按钮被隐藏,回车一样提交表单 【转】Eclipse安装SVN插件 [转]listview学习 安卓App程序访问网络 需要配置权限(java.net.SocketException: Permission denied) 【转】Android模拟器怎么配置网络连通 【转】Adobe Dreamweaver CS5序列号 【转】HTML特殊符号对照表 【转】ScriptX打印问题 Android SDK Manager无法更新的解决
.NET中TextBox控件设置ReadOnly=true后台取不到值的解决方法
独孤雁 · 2013-11-05 · via 博客园 - 独孤雁
在.NET 2.0 下,当页面上的某个TextBox 设置了属性ReadOnly="True"时,通过客户端脚本给其赋值后,在后台代码中访问其Text属性却无法获得该值。经过尝试,发现可以通过如下的方式解决这个问题:

方法一:不设置ReadOnly属性,通过onfocus=this.blur()来模拟,如下:
复制代码 代码如下:

<asp:TextBox ID="TextBox1" runat="server" onfocus=this.blur()></asp:TextBox>

在此情况下,当文本框获得焦点时便立刻失去,所以也无法手动修改其内容,能够模拟ReadOnly,在后台代码中也能通过Text属性,正常获取通过脚本在客户端设置的值;

方法二:设置了ReadOnly属性后,通过Request来取值,如下:
前台代码:
复制代码 代码如下:

<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" ></asp:TextBox>

后台代码:
复制代码 代码如下:

string Text = Request.Form["TextBox1"].Trim();

方法三:在Page_Load()正设置文本框的只读属性,在前台不设置。就能正常读取,如下:
复制代码 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TextBox1.Attributes.Add("readonly","true");
}
} 

 方法四:再就是通过js在客户端加个按钮事件,先去掉readonly属性,再激活提交按钮的click时间,在这里我用的jquery来处理的,也可以实现