473,327 Members | 2,071 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,327 software developers and data experts.

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(object sender, System.EventArgs e)
{
String userCtrlName = "Home";
System.Web.UI.Control userCtrl;
String id="";

pbdTemplate.TemplatePath = "layoutTemplate.ascx";

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

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

userCtrl = Page.LoadControl(userCtrlName);
content.Controls.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 2205
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(object sender, System.EventArgs e)
{
String userCtrlName = "Home";
System.Web.UI.Control userCtrl;
String id="";

pbdTemplate.TemplatePath = "layoutTemplate.ascx";

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

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

userCtrl = Page.LoadControl(userCtrlName);
content.Controls.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
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...
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: 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....
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...
2
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...
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.