473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Failed to Load ViewState?

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 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
I am using PageTemplate and dynamic load my user defined control.

Basically when user click on a linkbutton I will point back to
default.aspx with a parameter fID. then based on the fID to load ascx
into default.aspx page. Sometimes I will get the Failed to Load
ViewState error but not every time. Source code is attached, any help
please?

private void Page_Load(objec t sender, System.EventArg s e)
{
String userCtrlName = "Home";
System.Web.UI.C ontrol userCtrl;
String id="";

pbdTemplate.Tem platePath = "layoutTemplate .ascx";

if(Request.Para ms["fid"]!=null){
id = Request.Params["fid"].ToString ();

SqlStorage ss = new SqlStorage();
userCtrlName = ss.GetFunctionC ontrol(Convert. ToInt32(id));
}

userCtrl = Page.LoadContro l(userCtrlName) ;
content.Control s.Add(userCtrl) ;
}
I read some posts say disable viewstate, but this will disable most
events also (e.g. datagrid sorting...)

Thanks
-Rockdale

Jun 4 '06 #1
1 2229
Just assing some comments to my code
rockdale wrote:
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 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
I am using PageTemplate and dynamic load my user defined control.

Basically when user click on a linkbutton I will point back to
default.aspx with a parameter fID. then based on the fID to load ascx
into default.aspx page. Sometimes I will get the Failed to Load
ViewState error but not every time. Source code is attached, any help
please?

private void Page_Load(objec t sender, System.EventArg s e)
{
String userCtrlName = "Home";
System.Web.UI.C ontrol userCtrl;
String id="";

pbdTemplate.Tem platePath = "layoutTemplate .ascx";

if(Request.Para ms["fid"]!=null){
id = Request.Params["fid"].ToString ();

SqlStorage ss = new SqlStorage();
userCtrlName = ss.GetFunctionC ontrol(Convert. ToInt32(id));
}

userCtrl = Page.LoadContro l(userCtrlName) ;
content.Control s.Add(userCtrl) ; //Content is PlaceHolder
}
I read some posts say disable viewstate, but this will disable most
events also (e.g. datagrid sorting...)

Thanks
-Rockdale


Jun 4 '06 #2

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

Similar topics

3
2985
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 to load viewstate" error. This happens on Windows Server 2003. It happens erratically, and appears to happen after the application has been running (and in use) for some time. When the problem arises, it appears to happen more frequently for a...
0
2570
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 usercontrol into the place holder... i dont know why im getting this error:
9
21639
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
1
6605
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 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. Description: An unhandled exception occurred during the execution of the current web...
1
11748
by: Dhruba Bandopadhyay | last post by:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. The above message is what I get in my ASP.NET 2.0 page. I have debugging turned on and for those who want to see the stack trace, see below. In my old web site I had a frame set with a ASP page in left frame...
6
2931
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 has expired instead of getting the error? Thanks,
2
4489
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView Panel becomes visible. pnlGridViewSearchList pnlFormView The problem that I am having is that if I set the FormView Panel's
0
1651
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 item which was selected in the previous run the following error message is displayed.. Please help me in this regard.. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to...
2
10994
by: Rotsey | last post by:
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.
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.