asp.net TextBox只读时不能通过后台赋值取值解决办法
给页面的TextBox设置ReadOnly="True"时,在后台代码中不能赋值取值,下边几种方法可以避免:
1、不设置ReadOnly,设置onfocus=this.blur()
C#代码
<asp:TextBox ID="TextBox1" runat="server" onfocus=this.blur()></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server" onfocus=this.blur()></asp:TextBox>
文本框不变灰色,但也无法手动修改内容,可以在后台通过Text属性正常赋值取值
2、设置了ReadOnly属性后,通过Request来取值,如下:
前台代码:
C#代码
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" ></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" ></asp:TextBox>
后台代码:
C#代码
string Text = Request.Form["TextBox1"].Trim();
string Text = Request.Form["TextBox1"].Trim();
3、在Page_Load()正设置文本框的只读属性,能正常读取,如下:
C#代码
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TextBox1.Attributes.Add("readonly","true");
}
}
相关文档:
1.连接数据库文件
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />
SqlConnectionStringBuilder实例化时,要用到connectionString,如:SqlConnectionStringBuild builder = new SqlCon ......
* Copyright all(c) 2005 ZhongFeng, http://blog.csdn.net/SW515 */
public class ValidateCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
this.CreateCheckCodeImage(GenerateCheckCode());
}
&nb ......
ASP.NET Cookie 概述
Cookie 提供了一种在 Web 应用程序中存储用户特定信息的方法。例如,当用户访问您的站点时,您可以使用 Cookie 存储用户首选项或其他信息。当该用户再次访问您的网站时,应用程序便可以检索以前存储的信息。
什么是 Cookie?
Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之 ......
一、返回多个数据集
检查你的访问数据库的代码,看是否存在着要返回多次的请求。每次往返降低了你的应用程序的每秒能够响应请求的次数。通过在单个数据库请求中返回多个结果
集,可以减少与数据库通信的时间,使你的系统具有扩展性,也可以减少数据库服务器响应请求的工作 ......
1.
ClientScript.RegisterStartupScript(this.GetType(), "js1", "alert('删除成功');window.location='QuerySortList.aspx';", true);
2.
this.cmdSave.Attributes.Add("onclick", "return f_StringCheck()"); ......