Results 1 to 4 of 4

Thread: How to Completely Remove Viewstate in your ASP.NET page

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    How to Completely Remove Viewstate in your ASP.NET page

    VB Code:
    1. Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)
    2.  
    3.  
    4.  
    5.     End Sub
    6.  
    7.     Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
    8.         Return Nothing
    9.  
    10.     End Function
    11.  
    12.     Protected Overrides Function SaveViewState() As Object
    13.  
    14.         Return Nothing
    15.  
    16.     End Function
    Last edited by mendhak; Jun 23rd, 2008 at 01:59 AM.

  2. #2
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Arrow Re: How to Disable Viewstate in your ASP.NET page

    here is another code

    Code:
    To disable a page’s View State, add the code below in the Page class of the page. In this example, the page’s class name is ShowOrdersTablePage. 
    C#: 
    
    public ShowOrdersTablePage()
    {
        this.Init += new EventHandler(Page_Init);
    }
     
    private void Page_Init(object sender, System.EventArgs e)
    {
        this.EnableViewState = false;
    }
     
    
    
    Visual Basic .NET: 
    
    ' Disable the View State in the page.M
    Private Sub MyPage_Init_DisableViewState(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
        Me.EnableViewState = False
    End Sub
    thankx
    koolprasad20003
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Disable Viewstate in your ASP.NET page

    Hmm, I should mention that the first post completely removes all viewstate (you end up with a hidden field on the page called __viewstate, but no value). I must have made this thread in a rush, I will update it now.

  4. #4
    Member
    Join Date
    Jul 2019
    Location
    Ahmedabad
    Posts
    56

    Re: How to Disable Viewstate in your ASP.NET page

    ViewState can be disabled at the following levels:
    1. Control Level.
    2. Page Level.
    3. Application Level.

    (1) Disable ViewState at Control Level

    ViewState can be easily disabled for a particular control by setting EnableViewState property to False.
    Code:
    <asp:TextBox ID = "txtName" runat="server" EnableViewState = "false" />
    (2) Disable ViewState at Page Level
    ViewState can be disabled for the whole Page i.e. all controls on the Page by setting the EnableViewState property to False in the @Page Directive.
    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" EnableViewState = "false" %>
    (3) Disable ViewState at Application Level
    ViewState can be disabled for the whole Application i.e. all Pages by setting the enableViewState property to False in the pages section of the Web.Config file.
    Code:
    <system.web>
        <pages enableViewState="false">
        </pages>
    </system.web>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width