Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Failed to load viewstate

Reply
Thread Tools

Failed to load viewstate

 
 
R Reyes
Guest
Posts: n/a
 
      10-19-2005
Hi,

The question I'm asking revolves around what is needed to load a viewstate.

1) I am using Regular Expression Validators to validate text fields on a page.
--Let's say I have a form set up. After I type in "bad data" in a date
field and click submit, the validators will show up correctly with the errors
I programmed in red saying bad data was entered.
--Now, when I click on submit again (or even the back button) after
correcting the dates, I get the "Failed to load viewstate" error.

I've tried setting EnableViewState to both true and false but they don't
make a difference. Tutorials online are not helpful either as I think they
go into too much explanation about what a viewstate is, rather than how to
debug this common problem that I can't seem to get past.

I've coded a decent sized application for modifying Employee data and I
can't get passed this error. I'm not about to start from scratch
either...Can someone explain to me how I can stop this from happening?

Here is the stack trace (which I am also not very good at figuring out):
[HttpException (0x80004005): 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.UI.Control.LoadViewStateRecursive(Objec t savedState) +343
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
System.Web.UI.Page.LoadAllState() +527
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3940

Please help and post any comments as to what I'm doing wrong. Thanks in
advance.
 
Reply With Quote
 
 
 
 
R Reyes
Guest
Posts: n/a
 
      10-19-2005
I have 3 pages currently:
Directory.aspx (list of employees)
Profile.aspx (page for employee view/edit)
Update.aspx (saving changes)

Directory: This page uses a simple Datagrid bound to the recordset of
active employees. There are no errors here and no other controls created
besides the DataGrid.

---Directory.aspx->Profile.aspx...
Profile, part 1: This page uses a DataList. In ItemTemplate, the bound data
is read-only because you would have clicked on a particular employee from
Directory.aspx to view their information.

The only important tags/controls that are present in Profile.aspx are these:
1. EmployeeID: input type="hidden" name="EmployeeID"
value="<%#DataBinder.Eval(Container.DataItem, "EmployeeID")%>" />
2. ImageButton for Editing: asp:ImageButton runat="server" ID="ibtnEdit"
ImageUrl="images/button_up_edit.jpg" CommandName="Edit" />
3. Back button: img src="images/button_up_edit.jpg"
onClick="history.go(-1)"/>

--Profile.aspx(ItemTemplate)->Profile.aspx(EditItemTemplate)...
Profile, part 2: When a user clicks Edit, the new controls are "added" for
the user to make changes. I added several controls, TextBoxes,
DropDownLists, Validators all straight into the EditItemTemplate part. These
controls were not used in ItemTemplate (not sure if that makes a difference),
only EditItemTemplate

--Profile.aspx(EditItemTemplate)->Update.aspx...
Update.aspx: There is no datagrid or datalist present here. All I am doing
is creating 'asp:Label runat="server" ID="lblFullName"' tags and then using
code behind to take the incoming form values from Profile.aspx and set the
labels. Let's say I put in a bad date though, the page will render find
using the Validators presenting an error. But, if I change those values to
be valid I then get the Failed to load viewstate error...

So the flow of these 3 pages should be pretty straight forward. I am still
not good at understanding how controls *should* be created and the way I
should be using them. I appreciate your help and hope we can get this
figured out quickly. Thanks!

"Alvin Bruney - ASP.NET MVP" wrote:

> how are you adding your controls to the form? This really has nothing to do
> with the data you are entering. It's more of an issue with how the controls
> are created and what sort of preprocessing you do to them. I take it that
> these controls are probably dynamically created with some sort of low-level
> data manipulation?
>
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The Microsoft Office Web Components Black Book with .NET
> Now Available @ www.lulu.com/owc
> Forth-coming VSTO.NET - Wrox/Wiley 2006
> -------------------------------------------------------
>
>
>
> "R Reyes" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > The question I'm asking revolves around what is needed to load a

> viewstate.
> >
> > 1) I am using Regular Expression Validators to validate text fields on a

> page.
> > --Let's say I have a form set up. After I type in "bad data" in a date
> > field and click submit, the validators will show up correctly with the

> errors
> > I programmed in red saying bad data was entered.
> > --Now, when I click on submit again (or even the back button) after
> > correcting the dates, I get the "Failed to load viewstate" error.
> >
> > I've tried setting EnableViewState to both true and false but they don't
> > make a difference. Tutorials online are not helpful either as I think

> they
> > go into too much explanation about what a viewstate is, rather than how to
> > debug this common problem that I can't seem to get past.
> >
> > I've coded a decent sized application for modifying Employee data and I
> > can't get passed this error. I'm not about to start from scratch
> > either...Can someone explain to me how I can stop this from happening?
> >
> > Here is the stack trace (which I am also not very good at figuring out):
> > [HttpException (0x80004005): 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.UI.Control.LoadViewStateRecursive(Objec t savedState) +343
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Page.LoadAllState() +527
> > System.Web.UI.Page.ProcessRequestMain(Boolean
> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3940
> >
> > Please help and post any comments as to what I'm doing wrong. Thanks in
> > advance.

>
>
>

 
Reply With Quote
 
 
 
 
R Reyes
Guest
Posts: n/a
 
      10-19-2005
My last post was a bit longer, so in short I will just say:
Yes, they are dynamically created when a user clicks on the edit button
because it runs the EditItemTemplate part of the Profile.aspx page, where
ItemTemplate doesn't have any controls. And that's where I come to the
problem of understanding viewstate...

"Alvin Bruney - ASP.NET MVP" wrote:

> how are you adding your controls to the form? This really has nothing to do
> with the data you are entering. It's more of an issue with how the controls
> are created and what sort of preprocessing you do to them. I take it that
> these controls are probably dynamically created with some sort of low-level
> data manipulation?
>
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The Microsoft Office Web Components Black Book with .NET
> Now Available @ www.lulu.com/owc
> Forth-coming VSTO.NET - Wrox/Wiley 2006
> -------------------------------------------------------
>
>
>
> "R Reyes" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > The question I'm asking revolves around what is needed to load a

> viewstate.
> >
> > 1) I am using Regular Expression Validators to validate text fields on a

> page.
> > --Let's say I have a form set up. After I type in "bad data" in a date
> > field and click submit, the validators will show up correctly with the

> errors
> > I programmed in red saying bad data was entered.
> > --Now, when I click on submit again (or even the back button) after
> > correcting the dates, I get the "Failed to load viewstate" error.
> >
> > I've tried setting EnableViewState to both true and false but they don't
> > make a difference. Tutorials online are not helpful either as I think

> they
> > go into too much explanation about what a viewstate is, rather than how to
> > debug this common problem that I can't seem to get past.
> >
> > I've coded a decent sized application for modifying Employee data and I
> > can't get passed this error. I'm not about to start from scratch
> > either...Can someone explain to me how I can stop this from happening?
> >
> > Here is the stack trace (which I am also not very good at figuring out):
> > [HttpException (0x80004005): 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.UI.Control.LoadViewStateRecursive(Objec t savedState) +343
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Page.LoadAllState() +527
> > System.Web.UI.Page.ProcessRequestMain(Boolean
> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3940
> >
> > Please help and post any comments as to what I'm doing wrong. Thanks in
> > advance.

>
>
>

 
Reply With Quote
 
R Reyes
Guest
Posts: n/a
 
      10-20-2005
Not sure if you're still looking into this but I came across an article that
said the controls need to be added first before setting their
properties/values.

Does this mean that the code to dynamically add controls must be in the .cs
file? I have them hardcoded with "asp:Control" tags in the .aspx file
however for some controls like DataList, the controls are ONLY used in the
EditItemTemplate part of the code (where they get created because a user
would have clicked "edit") whereas the ItemTemplate part is only used for
displaying values from the database, not modifications.

Maybe I have to add all the controls programmatically with C# only and not
hardcoded with ASP.NET to prevent that viewstate error?

"Alvin Bruney - ASP.NET MVP" wrote:

> how are you adding your controls to the form? This really has nothing to do
> with the data you are entering. It's more of an issue with how the controls
> are created and what sort of preprocessing you do to them. I take it that
> these controls are probably dynamically created with some sort of low-level
> data manipulation?
>
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The Microsoft Office Web Components Black Book with .NET
> Now Available @ www.lulu.com/owc
> Forth-coming VSTO.NET - Wrox/Wiley 2006
> -------------------------------------------------------
>
>
>
> "R Reyes" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > The question I'm asking revolves around what is needed to load a

> viewstate.
> >
> > 1) I am using Regular Expression Validators to validate text fields on a

> page.
> > --Let's say I have a form set up. After I type in "bad data" in a date
> > field and click submit, the validators will show up correctly with the

> errors
> > I programmed in red saying bad data was entered.
> > --Now, when I click on submit again (or even the back button) after
> > correcting the dates, I get the "Failed to load viewstate" error.
> >
> > I've tried setting EnableViewState to both true and false but they don't
> > make a difference. Tutorials online are not helpful either as I think

> they
> > go into too much explanation about what a viewstate is, rather than how to
> > debug this common problem that I can't seem to get past.
> >
> > I've coded a decent sized application for modifying Employee data and I
> > can't get passed this error. I'm not about to start from scratch
> > either...Can someone explain to me how I can stop this from happening?
> >
> > Here is the stack trace (which I am also not very good at figuring out):
> > [HttpException (0x80004005): 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.UI.Control.LoadViewStateRecursive(Objec t savedState) +343
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState)

> +142
> > System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +290
> > System.Web.UI.Page.LoadAllState() +527
> > System.Web.UI.Page.ProcessRequestMain(Boolean
> > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3940
> >
> > Please help and post any comments as to what I'm doing wrong. Thanks in
> > advance.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors: Failed to load viewstate. & Validation of viewstate MAC failed. sck10 ASP .Net 6 09-01-2006 05:59 PM
Failed to load viewstate. The control tree into which viewstate... Josema ASP .Net Building Controls 2 05-22-2005 10:38 AM
Failed to load viewstate. The control tree into which viewstate... Josema ASP .Net Web Controls 0 05-09-2005 10:58 AM
Failed to load viewstate (i.e., I'm doomed). Mike Hnatt ASP .Net 2 11-03-2003 08:27 PM
Failed to load ViewState John Kirksey ASP .Net 5 07-22-2003 03:06 PM



Advertisments