LoadViewstate Error

G

Guest

Hi,

When I’m trying to switch from Presentation Mode to Author Mode, at that
point a control is loaded in a custom place holder and I’m getting this
error:

SYSTEM_EXCEPTION:Failed to load viewstate.

The control tree into which viewstate is being loaded must match the control
tree that was used to save viewstate during the previous request.

For example, when adding controls dynamically, the controls added during a
post-back must match the type and position of the controls

added during the initial request.:

System.Web.HttpException: Failed to load viewstate.

The control tree into which viewstate is being loaded must match the control
tree that was used to save viewstate during the previous request.

For example, when adding controls dynamically, the controls added during a
post-back must match the type and position of the controls added during the
initial request. at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState) at System.Web.UI.Control.LoadViewStateRecursive(Object
savedState) at System.Web.UI.Control.AddedControl(Control control, Int32
index) at System.Web.UI.ControlCollection.Add(Control child) at
Com.MphasiS.JetAirways.TravelPortal.Web.CustomPlaceholders.JetTPPHFAQ.CreatePresentationChildControls(BaseModeContainer
presentationContainer) in
c:\inetpub\wwwroot\jettravelportal\customplaceholders\jettpphfaq.cs:line 79

Code for Authoring and Presentation Mode is:

protected override void CreateAuthoringChildControls(BaseModeContainer
authoringContainer)
{
try
{
authorisationGrid
=(UCFAQ)Page.LoadControl("../UserControls/UCFAQ.ascx");


authoringContainer.Controls.Add(authorisationGrid );

}

catch(System.Exception sysEx)
{
//catch code
}
}

protected override void CreatePresentationChildControls(BaseModeContainer
presentationContainer)
{
try
{
postingNav =(UCFAQPostingNav)
Page.LoadControl("../UserControls/UCFAQPostingNav.ascx");


presentationContainer.Controls.Add(postingNav);

presentationGrid =(UCFAQsSummary)
Page.LoadControl("../UserControls/UCFAQsSummary.ascx");


presentationContainer.Controls.Add(presentationGrid);

}
catch(System.Exception sysEx)
{
//catch code
}
}

Actually, in my module, in both the modes, i.e. Authoring and Presentation,
the way in which we are presenting data is different. So when I’m trying to
switch from Presentation to Authoring mode or vise-versa, it is throwing an
exception.

How can I solve it, please advice.

Thanks,
Pooja.
 
S

S. Justin Gengo

Pooja,

If you add a control dynamically you need to add it again on post back.

I have a a couple of short samples of dynamically adding controls to a page
on my site, www.aboutfortunate.com, click the "Code Library" link at the top
of the page and then type into the search box there "Dynamic Control" and
you'll see the samples.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

Load the control again in the postback and if you dynamically add a control
also give it an ID. If you don't give the control an ID you can get troubles
handling page events on the control.
 
G

Guest

Hi,

Thnx for the replies.

I tried the way both of u have explained in your mails. I tried loading all
the controls at all times and then making them visible / invisible according
to the requirement. But i was still getting the same error.

Disabling the viewstate of the controls helped me but then the problem is -
i have a grid control in one of the user controls that is being loaded. if i
disable the viewstate, the Grid_ItemCommand stops firing when i click on the
"Edit" and "Delete" buttons. Is there a workaround for that.

Thnx,
Pooja.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Failed to load viewstate 2
Problem with ViewState ? 2
view state error 2
Exception 0
Viewstate error when adding user controls 2
Failed to load view state 1
Regarding An Error 0
Failed to load ViewState 5

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top