欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

aspx不显示ViewState的实例

程序员文章站 2024-03-02 18:31:10
复制代码 代码如下:system.io.stringwriter html = new system.io.stringwriter();   ...
复制代码 代码如下:

system.io.stringwriter html = new system.io.stringwriter();
             system.web.ui.htmltextwriter tw = new system.web.ui.htmltextwriter(html);
             base.render(tw);
             string temp = html.tostring();
             string s1 = string.empty, s2 = string.empty, s3 = string.empty, s4 = string.empty, s5 = string.empty, s6 = string.empty;
             int i = 0;
             int j = 0;

             i = temp.indexof("<form");
             if (i > 0)
             {
                 j = temp.indexof(">", i);
                 s1 = temp.substring(0, i);
                 s2 = temp.substring(j + 1, temp.length - j - 1);
             }

             i = s2.indexof("<input type=\"hidden\" name=\"__viewstate\" id=\"__viewstate\"");
             if (i > 0)
             {
                 j = s2.indexof(">", i);
                 s3 = s2.substring(0, i);
                 s4 = s2.substring(j + 1, s2.length - j - 1);
             }

             i = s4.indexof("<input type=\"hidden\" name=\"__eventvalidation\" id=\"__eventvalidation\"");
             if (i > 0)
             {
                 j = s4.indexof(">", i);
                 s5 = s4.substring(0, i);
                 s6 = s4.substring(j + 1, s4.length - j - 1);
                 temp = s1 + s3 + s5 + s6;
             }
             else
             {
                temp = s1 + s3 + s4;
             }
             temp = temp.replace("</form>", "");
             temp = temp.replace("\r\n", "");
             tw.close();
             response.write(temp);