473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Failed to load viewstate - user controls

Hi,

I have a web site that uses user controls to display different formats of
timesheets.

I have a browse page that has prev/next buttons to browse through a set of
timesheets.

As I say they can be different user controls for each timesheet type.

The problem is when I navigate (prev/next) from one type of user control to
the next type
I get this error

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.

The thing is strange is that say the first user control is for monthly
timesheets and then I click next to goto
a weekly timesheet (different user control) it is fine. But when i go back
to the first monthly timsheet
again it gives this error.

Help!!
rotsey
Dec 4 '07 #1
2 10968
when viewstate is loaded after a postback, it looks for controls with
the same name and type to load.

if you dynamically change the user control you can get this error. you
should keep track of which control you rendered (say a flag in
viewstate) and recreate the control in oninit. then in onload/prerender
if you change the control, delete the old one and add the new one.

-- bruce (sqlwork.com)

Rotsey wrote:
Hi,

I have a web site that uses user controls to display different formats of
timesheets.

I have a browse page that has prev/next buttons to browse through a set of
timesheets.

As I say they can be different user controls for each timesheet type.

The problem is when I navigate (prev/next) from one type of user control to
the next type
I get this error

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.

The thing is strange is that say the first user control is for monthly
timesheets and then I click next to goto
a weekly timesheet (different user control) it is fine. But when i go back
to the first monthly timsheet
again it gives this error.

Help!!
rotsey

Dec 4 '07 #2
On Dec 4, 4:31 am, "Rotsey" <malcolm_sm...@RemoveThis.optusnet.com.au>
wrote:
Hi,

I have a web site that uses user controls to display different formats of
timesheets.

I have a browse page that has prev/next buttons to browse through a set of
timesheets.

As I say they can be different user controls for each timesheet type.

The problem is when I navigate (prev/next) from one type of user control to
the next type
I get this error

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.

The thing is strange is that say the first user control is for monthly
timesheets and then I click next to goto
a weekly timesheet (different user control) it is fine. But when i go back
to the first monthly timsheet
again it gives this error.

Help!!
rotsey
This problem arise when you dynamic create child control and for this
create use some variable. After postback this variable has old value
that give at Initialize method. To fix this problem need recover this
varible, for this use SaveControlState, LoadControlState.

Example
public class UniversalFilterControl1 : WebControl
{

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.RegisterRequiresControlState(this);
}

protected override void LoadControlState(object savedState)
{
object[] list = savedState as object[];
base.LoadControlState(list[0]);
if (list[1] != null)
<some varible= list[1];
}

protected override object SaveControlState()
{
object[] list = new object[2];
list[0] = base.SaveControlState();
list[1] = <some varible>;
}
}

Dec 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eamonn O'Connell | last post by:
Hi, We have an ASP.net application, where we dynamically add controls, in the Page_Load. Occasionally, when the user posts back the page (e.g. clicks Save button on the page), we get a "Failed...
0
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
1
by: et | last post by:
I. 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...
1
by: rockdale | last post by:
Sometime my ASP.NET application got this error message but not always everytime. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that...
6
by: sck10 | last post by:
Hello, I have applications that produce the following error when they have been open to long without activity. Is there any way to force a re-load of the page or go to another page if the page...
4
by: scottcly | last post by:
I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to...
0
by: nithagowda | last post by:
Hello, I have a DropDownList for source type and a panel for displaying TreeView based on the source type.. The problem is- if i select different source type drom ddlSrcType, other than the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.