By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

GridView & FormView: Failed to load viewstate

P: n/a
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();
}

}
Nov 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Nov 23 '06 #2

P: n/a
Thanks Walter...
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:mn**************@TK2MSFTNGXA01.phx.gbl...
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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Nov 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.