此页的状态信息无效,可能已损坏 的处理办法及原因分析

2019-12-14,,,,,

当时的情况是这样的:


a.aspx页面 执行一个URL字符串访问b.aspx 然后 b页面返回一个值给a


a.aspx.cs的一段代码
复制代码 代码如下:
                            string result = "";
                            string url = "http://localhost:1759/textWeb/b.aspx";
                            result =exec_url(url);
                            Label1.Text = result;


    public string exec_url(string url)
    {


        string result = "1";
        WebRequest request = WebRequest.Create(url);
        try
        {
            request.Timeout = 20000;//20秒超时
            WebResponse response = request.GetResponse();


            Stream resStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(resStream);
            result = sr.ReadToEnd();
            sr.Close();
            resStream.Close();
        }
        catch
        {
            return "1";
        }
        return result;


    }

b.aspx页面代码:
复制代码 代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

   
    </div>
    </form>
</body>
</html>

b.aspx.cs代码如下:
复制代码 代码如下:
public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("你好 哈哈!");
    }
}

运行时:第一次Label内容显示正常 但当你不刷新页面再点击按钮时候就提示


System.Web.HttpException: 此页的状态信息无效,可能已损坏


问题原因:


原来是这样的:第一次label加载内容时加载的内容为b.aspx


<form>


你好 哈哈!


</form>


再次点击时原理应该是这个样子的:


<form>


你好 哈哈!


<form>


你好 哈哈!


</form>


</form>


所以就出错了呀!


解决办法为:去掉b.aspx中的form标签

《此页的状态信息无效,可能已损坏 的处理办法及原因分析.doc》

下载本文的Word格式文档,以方便收藏与打印。