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 9123113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:15:39+00:00 2026-06-17T06:15:39+00:00

i use asp.net and this code in aspx page: public partial class Default :

  • 0

i use asp.net and this code in aspx page:

public partial class Default : System.Web.UI.Page
{
    string _Name;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            _Name = "Maikel";
            ViewState["Name"] = _Name;
        }
    }

    protected void btnAddName_Click(object sender, EventArgs e)
    {
        if (ViewState["Name"] == null)
        {
            txtName.Text = "Empty";
        }
        else
        {
            txtName.Text = ViewState["Name"].ToString();
        }
    }
}

its OK. and display “Maikel” in textbox.
But when I use this code:

<%@ Page Language="C#" AutoEventWireup="true" **ViewStateMode="Disabled" EnableViewState="true**" CodeBehind="Default.aspx.cs" Inherits="WebApplication3.Default" %>

ViewState["Name"] is Empty! and display “Empty” in textbox. why?

plese help me for use ViewState with ViewStateMode="Disabled" EnableViewState="true".

Edit:

I use master page and (web from use master page), and write this code in master page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" ViewStateMode="Disabled" EnableViewState="true" Inherits="WebApplication3.Site1" %>

and code ViewState["Name"] in code behind page(web from use master page), ViewState is not Empty!! why?

  • 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-06-17T06:15:40+00:00Added an answer on June 17, 2026 at 6:15 am

    In your case you have disabled the ViewState property for the whole page by setting ViewStateMode="Disabled" at page level. That is why you are not getting anything in the view state.

    ASP.NET View State Overview

    To disable view state by default for an entire page, set the
    ViewStateMode attribute of the @ Page directive to Disabled.

    Control.ViewStateMode Property (MSDN)

    To disable view state for a page and to enable it for a specific
    control
    on the page, set the EnableViewState property of the page
    and the control to true, set the ViewStateMode property of the page to
    Disabled, and set the ViewStateMode property of the control to
    Enabled.

    The ViewStateMode property of a page or a control has an effect only
    if the EnableViewState property is set to true. If the EnableViewState
    property is set to false, view state will be turned off even if the
    ViewStateMode property is set to Enabled.

    EDIT:
    To Use ViewState in Page.

    You can place all your controls inside a panel, and for that panel you can set the ViewState to false. At Page level enable ViewStateMode and you will be able to use the ViewState in the code behind

    For MasterPage you can disable the ViewState on ContentPlaceHolder

    <asp:ContentPlaceHolder ID="HeadContent" runat="server" EnableViewState="false">
    </asp:ContentPlaceHolder>
    

    and at Master page level enable the ViewStateMode

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In ASP.NET MVC (default routing),I'd like to use a URL like this to return
I am developing an asp.net web site. I have an aspx page. I want
I am using ASP.NET Web Forms/C# .I am having a page Customer.aspx .I have
I am writing a web app in asp.net. I have an aspx page that
I am creating a model binder to use with asp.net mvc. This is what
how can i use request.querystring in asp.net.i have a linkbutton and this is in
Is it possible to use this Role Provider AspNetWindowsTokenRoleProvider with ASP.NET FORMS Authentication (via
I'm trying to use the Facebook assemblies in ASP.NET MVC 3. I'm following this
I use asp.net script manager in master page to add js files . In
I use ASP.NET and have a label control on my page, which I fill

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.