Home »

Disable Viewstate of a page (No postback) in C# .NET


Simply add this function in the code behind of that page
protected override void Render(HtmlTextWriter output)
        {
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
            base.Render(textWriter);
            textWriter.Close();
            string strOutput = stringWriter.GetStringBuilder().ToString();
            strOutput = Regex.Replace(strOutput, "<input[^>]*id=\"__VIEWSTATE\"[^>]*>", "", RegexOptions.Singleline);
            output.Write(strOutput);
        }

Hope this entry help you!
If you found any mistake or error in this entry, please let me know. I'll try to fix that a.s.a.p.
Any solution is highly appreciated!

-Share2Learn-

No comments:

Post a Comment