GridView & FormView: Failed to load viewstate

S

sck10

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
visibility to false after I update a record, I get the "Failed to load
viewstate" error the next time I click on a GridView record. This only
happens when I do an update. If I select cancel from the ReadOnly mode, the
page works fine.

protected void fvDetail_ItemUpdated(object sender,
FormViewUpdatedEventArgs e)
{
//this.pnlFormView.Visible= false;
this.gvSearchList.DataBind();
}

My question is how can I hide the FormView Panel after I update a record
without getting the "Failed to load viewstate" error?

Any help with this would be appreciated.

Thanks, sck10


The error:
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.


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class highlight: System.Web.UI.Page
{
//SQL Server Connection String
public string strConnSqlSCK10 =
ConfigurationManager.ConnectionStrings["cnnSCK10"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)
{
if (! this.Page.IsPostBack) this.pnlGridViewSearchList.Visible = true;
}

protected void gvSearchList_SelectedIndexChanged(object sender, EventArgs
e)
{
//this.AppCodeHidePanels();
this.pnlFormView.Visible= true;
}

protected void fvDetail_ItemUpdating(object sender,
FormViewUpdateEventArgs e)
{
e.NewValues["UpdatedBy"] = "sck10";
e.NewValues["DateUpdated"] = DateTime.Now.ToString();
}

protected void fvDetail_ItemUpdated(object sender,
FormViewUpdatedEventArgs e)
{
//this.pnlFormView.Visible= false;
this.gvSearchList.DataBind();
}

}
 
W

Walter Wang [MSFT]

Hi,

From the error description, it seems related to control tree get changed
between viewstate saving and loading phases. However, from the code you
posted, I cannot see apparent causes. You might have to send me more
complete code to inspect. Thanks.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

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.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top