472,146 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

GridView & FormView: Failed to load viewstate

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
2 4364
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
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.

Similar topics

1 post views Thread by Kyle K. | last post: by
1 post views Thread by joechipubik | last post: by
reply views Thread by ThePurpleCat | last post: by
5 posts views Thread by =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.