Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:09:06+00:00 2026-05-24T13:09:06+00:00

I want to remove the view state using the method below. My problem is

  • 0

I want to remove the view state using the method below. My problem is I don’t like it put the code below into almost every page. I like to move it to the masterpage or convert it to a class and run it from the masterpage.
The code below on works on the non-masterpage .
It will have this problem if I put inside the masterpage CS0115: ‘MasterPage.SavePageStateToPersistenceMedium(object)’: no suitable method found to override

#region Disable ViewState
protected override void SavePageStateToPersistenceMedium(object state)
{
}
protected override object LoadPageStateFromPersistenceMedium()
{
    return null;
}
#endregion
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:09:06+00:00Added an answer on May 24, 2026 at 1:09 pm
        //using the below you will need to change  asp:ImageButton coding method. You need to convert it to a regular submit button. There may be other problems which i don't now yet.
    

    Place the code below on the master page.

         protected override void Render(HtmlTextWriter writer)
        {///Articles/How-to-disable-or-remove-ViewState-Hidden-Field-in-ASP.Net-Page.aspx
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter ht = new HtmlTextWriter(sw);
            base.Render(ht);
            string html = sb.ToString();
            //The remove the value and it id from the view status this next line
            html = Regex.Replace(html, "<input[^>]*id=\"(__VIEWSTATE)\"[^>]*>", "<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"\"/>", RegexOptions.IgnoreCase);
            //To completely remove the view state use the line below
           // html = Regex.Replace(html, "<input[^>]*id=\"(__VIEWSTATE)\"[^>]*>", "", RegexOptions.IgnoreCase);
            writer.Write(html);
            sb = null; html = null; ht.Dispose(); sw.Dispose();
        }
    

    Use this technique to detect the clicked button on your aspx page(not the master page). Place this code in the code behind
    if (Request.Form[“nonPostBackButton1.y”] != null)
    {
    Response.Write(“
    nonPostBackButton1 is just pressed“);
    }

            if (Request.Form["nonPostBackButton2.y"] != null)
            {
                Response.Write("<br/><b>nonPostBackButton2 is just pressed</b>");
            }
    

    This is the sample of the image submit buttons

    <input type="image" alt="nonPostBackButton1"  name="nonPostBackButton1"/>&nbsp; Use this method instead of the postback buttons. This is the image submit button 1</p>
    <p><input type="image" alt="nonPostBackButton2"  name="nonPostBackButton2"/>&nbsp; Use this method instead of the postback buttons. This is the image submit button 1</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to flip my view. but the problem is when
I want to remove if-statements from my View, but I'm having problems with predefined
I want remove "Language" querystring from my url. How can I do this? (using
I want to remove the current subview (added atIndex:0) from my root view controller
I want to remove viewstate from page completely without using MVC pattern. I am
If I want to remove an item from my list view by tapping it,
I have a problem with a view I want to create. I have two
I want to remove the title area section which is above view all site
I have a UILabel in my view. I want to remove the UILabel if
I want to remove a UIView from a superview and add it again at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.