Failed to Load ViewState?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rockdale

    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

  • rockdale

    #2
    Re: Failed to Load ViewState?

    Just assing some comments to my code
    rockdale wrote:[color=blue]
    > 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[/color]

    Comment

    Working...