我没有JQuery或其他JavaScript更改值或html结构。我没有动态添加的控件。ASP.NET错误:状态信息对此页无效,可能已损坏
尽管如此,我得到的错误:状态信息是这个页面无效,可能已损坏
出现的错误有些随机。这里是我可以复制的问题,ASPX文件:
<%@ Page ViewStateEncryptionMode ="Never" MaxPageStateFieldLength="40" ValidateRequest="false" Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="tbTest.aspx.cs" Inherits="_Default" %>
<!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">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>tbTest </title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button id="Submit1" type="submit"
runat="server" onClick="btnclick_Click" Text="Submit" /><br />
<asp:TextBox ID="tbStatus" enableViewState="true" runat="server" TextMode="MultiLine"
Width="617px" Height="67px" ReadOnly="True" Font-Size="Smaller"></asp:TextBox>
<br />
</form>
</body>
</html>
的.cs文件:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DateTime timestamp = DateTime.Now;
try
{
tbStatus.Text = timestamp.ToString() + ". Page Loaded. ";
}catch (Exception ex) {
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
Response.Cache.SetNoStore();
} catch (Exception ex){
}
}
}
protected void btnclick_Click(object sender, EventArgs e)
{
DateTime timestamp = DateTime.Now;
try
{
tbStatus.Text += Environment.NewLine + timestamp.ToString() + ". TextBox updated. ";
} catch (Exception ex) {
tbStatus.Text += Environment.NewLine + timestamp.ToString() + ". Error. " + ex.Message.ToString();
}
}
}
这真的让我头疼。 3-4提交后出现错误。我已经测试了ViewStateEncryptionMode,MaxPageStateFieldLength,ValidateRequest,AutoEventWireup和EnableEventValidation没有成功。
什么可能是错的?
谢谢!我不明白为什么,但保存会话中的viewState解决了它!: 'protected override object LoadPageStateFromPersistenceMedium() { return Session [“_ ViewState”]; } protected override void SavePageStateToPersistenceMedium(object viewState) {[_ViewState“] = viewState; }' – Plarsen
Downvoted只是建议关闭事件验证。在大多数商业案例中这不是一个可以接受的答案。 – ctb3
@ ctb3说得好。在大多数商业案例中,但并非在所有情况下。 – StackTrace