johna
johna

Reputation: 10752

ViewStateMode not working as expected

On an ASP.NET 4.0 website I am working on I have a master page where I have set ViewStateMode="Disabled". There is then a nested master page for one section of the site where ViewStateMode="Enabled" as ViewState is required for much of this part of the site. On child pages for this section ViewState is not being maintained for controls like DropDownList.

There are no other ViewState directives anywhere else on these master pages or child pages.

Master page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Internet.Site" ViewStateMode="Disabled" %>

Nested master page:

<%@ Master Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Tvet.master.cs" Inherits="Internet.Tvet.Tvet" ViewStateMode="Enabled" %>

I can get ViewState working if I add ViewStateMode="Enabled" to each control or a panel surrounding the controls, but my understanding is that all controls inherit the parent ViewStateMode setting.

Is this behaviour correct or am I doing something wrong?

Upvotes: 0

Views: 768

Answers (1)

Jupaol
Jupaol

Reputation: 21365

To fix it, simply change the ViewStateMode property of the ContentPlaceHolder control

Example:

In master page

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" ViewStateMode="Enabled">

</asp:ContentPlaceHolder>

Upvotes: 1

Related Questions