Failed to load viewstate HttpException after calling FormView.UpdateItem(true);

J

J055

Hi

I need some help with this one. If I add this LinkButton Command event I get
an 'System.Web.HttpException: Failed to load viewstate' on the second
postback. It only occurs when FormView1.UpdateItem(true) is called. The page
posts back OK. When I do a second PostBack I get the error.

protected void LinkButtonPrevNext_Command(object sender,
CommandEventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
FormView1.UpdateItem(true);
}
//...other bits
}

As far as I know I am not loading any Controls dynamically. I'm finding it
almost impossible to debug and find out why the controls are different.

What's the best way to isolate the problem?

Thanks
Andrew
 
S

Steven Cheng[MSFT]

Hello Andrew,

From your description, you're getting "System.Web.HttpException: Failed to
load viewstate...." exception when manually use a button to trigger the
FormView's UpdateItem command, correct?

According to the code logic you mentioned, I have performed some simple
test on my local side and it seems a very simple and typical FormView
editing/updating webform can not quite repro the exact error behavior. My
test result is as below:

I use a FormView to edit and update a very simple table in SQL Server, the
autogenerated edit/update interface(inside formview works well).

And then I put a button on the webform(out side of the formview) and add
code to manually update the FormView item:

protected void btnOutUpdate_Click(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
FormView1.UpdateItem(true);
}
}

it also works without any problem. Therefore, I think the problem is
likely specific to the data table or anything else on the webform. I
suggest you try simplify the page step by step to isolate the cause.

If you have any new finding or anything we can help, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

J055

Hi Steven

I solved the problem by adding FormView1.DataBind below the UpdateItem
method. My code creates and event when the UpdateItem occurs to tell the
Parent page to switch to another View in a MultiView control. If I don't
change the view then the error doesn't occur.

The MultiView control contains 4 views with their own user control. I'm
still not sure why DataBinding would solve the problem and why the error
occurs when the MultiView.ActiveViewIndex is changed.

Thanks
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top