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

推荐订阅源

GbyAI
GbyAI
爱范儿
爱范儿
Y
Y Combinator Blog
T
Tor Project blog
V
Visual Studio Blog
U
Unit 42
B
Blog RSS Feed
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
G
Google Developers Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
博客园_首页
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
P
Proofpoint News Feed
Jina AI
Jina AI
博客园 - 【当耐特】
S
Security @ Cisco Blogs
I
Intezer
MyScale Blog
MyScale Blog
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
腾讯CDC
T
Tenable Blog
A
Arctic Wolf
T
Threat Research - Cisco Blogs
S
Securelist
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
C
Check Point Blog
NISL@THU
NISL@THU
Microsoft Security Blog
Microsoft Security Blog
V
Vulnerabilities – Threatpost

博客园 - 独孤雁

在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来处理的,也可以实现