不是说 viewstate是用来维持页面状态的吗?但为什么 我把 enableviewstate 设置成 false 提交页面后 页面的状态还在 就是 textbox中的值还在页面中显示着<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
解决方案 »
- 这个问题不知道在那个版块发贴,一个TAB标签切换更换图片的操作
- visual c# command line compiler已停止工作
- 急~ 水晶报表 -柱状图- 问题 !!! (★★★★★)
- CrystalReportViewer1:未知的服务器标记“cr:CrystalReportViewer”
- 如何让DropDownList显示在表格后面,让DropDownList不可见
- DataGrid中不响应OnUpdateCommand和OnCancelCommand(急 在线等 忙了两天的)
- 像JSON是怎么处理输入特殊字符的
- 超级莱sql语名。谢谢
- 一个页有两个datagrid,怎样设置当一个显示的时候,另一个隐藏,另一个显示,第一个隐藏,谢谢!
- 将网站打包成一个exe文件安装
- 网站效率的问题请教
- 请教2个面试问题
不能通过Form提交回服务器端的数据 比如Textbox的BackColor看下面这个例子 页面上有两个按钮 其中一个改变文本框的背景色 另一个只单纯产生一个postback
1. 当TextBox1的EnableViewState=true时,先点击第一个按钮,TextBox1的背景色变为红色;之后再点击第二个按钮,TextBox1的背景色还是红色,是因为BackColor这个属性被保存到ViewState里
2. 当TextBox1的EnableViewState=false时,先点击第一个按钮,TextBox1的背景色变为红色;之后再点击第二个按钮,TextBox1的背景色没了,是因为ViewState不起作用
无论哪种情况,由于TextBox1的Text属性是通过Form提交给服务器端的(即PostbackData),因此都不会消失aspx代码
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="false"></asp:TextBox><br />
<asp:Button ID="btnChangeColor" runat="server" Text="改变文本框背景色"
onclick="btnChangeColor_Click" /><br />
<asp:Button ID="btnPostback" runat="server" Text="产生一次Postback" />aspx.cs代码
protected void btnChangeColor_Click(object sender, EventArgs e)
{
TextBox1.BackColor = System.Drawing.Color.Red;
}