473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Failed to Load Viewstate Error

I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to control which one is visible based on buttons pushed. I can do single operations, but I get an error when I click SELECT on the GRIDVIEW, then UPDATE on the DetailsView then SELECT on the Gridview again.

I will have to send the script in a follow-on message, but here are the code behind and the error details.

Thanks.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class Member_Administrator_Product_States : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.  
  17.     }
  18.   protected void cmdAdd_Click(object sender, EventArgs e)
  19.   {
  20.     pnlGrid.Visible = false;
  21.     DetailsView1.ChangeMode(DetailsViewMode.Insert);
  22.     pnlDetail.Visible = true;
  23.   }
  24.   protected void cmdSelect_Click(object sender, EventArgs e)
  25.   {
  26.     pnlGrid.Visible = false;
  27.     DetailsView1.ChangeMode(DetailsViewMode.Edit);
  28.     pnlDetail.Visible = true;
  29.   }
  30.   protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
  31.   {
  32.     if (e.Exception != null)
  33.     {
  34.       lblErrorMsg.Text = "Invalid data. Please correct and try again.";
  35.       e.ExceptionHandled = true;
  36.       e.KeepInEditMode = true;
  37.     }
  38.     else if (e.AffectedRows == 0)
  39.       lblErrorMsg.Text = "Another user updated that category. Please try again.";
  40.   }
  41.   protected void DetailsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
  42.   {
  43.     if (e.Exception != null)
  44.     {
  45.       lblErrorMsg.Text = e.Exception.Message;
  46.       e.ExceptionHandled = true;
  47.     }
  48.     else
  49.       if (e.AffectedRows == 0)
  50.         lblErrorMsg.Text = "Another user updated that category. Please try again.";
  51.   }
  52.   protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
  53.   {
  54.     if (e.Exception != null)
  55.     {
  56.       lblErrorMsg.Text = "Invalid data. Please correct and try again.";
  57.       e.ExceptionHandled = true;
  58.       e.KeepInInsertMode = true;
  59.     }
  60.     else if (e.AffectedRows == 0)
  61.       lblErrorMsg.Text = "Another user updated that category. Please try again.";
  62.   }
  63.   protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
  64.   {
  65.     switch (e.CommandName) { 
  66.       case "Cancel":
  67.       case "Update":
  68.       case "Insert":
  69.         pnlGrid.Visible = true;
  70.         pnlDetail.Visible = false;
  71.         break;
  72.       default:
  73.         break;
  74.     }
  75.   }
[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) +355
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Control.LoadChildViewStateByIndex(Ar rayList childState) +142
System.Web.UI.Control.LoadViewStateRecursive(Objec t savedState) +303
System.Web.UI.Page.LoadAllState() +505
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2543
Sep 14 '06 #1
4 5372
I am a first-time poster and am having trouble posting the script. I get the following message even though there are no image tags in my script or my signature.

You have included too many images in your signature or in your previous post. Please go back and correct the problem and then continue again.

Images include use of smilies, the vB code [img] tag and HTML <img> tags. The use of these is all subject to them being enabled by the administrator.
Sep 14 '06 #2
Here is the GridView portion of the script:

Expand|Select|Wrap|Line Numbers
  1.       <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="odsState" DataKeyNames="StateID">
  2.         <Columns>
  3.           <asp:TemplateField ShowHeader="False">
  4.             <HeaderTemplate>
  5.               <asp:Button ID="cmdAdd" runat="server" CausesValidation="False" CommandName="Add" Text="Add" Width="60" OnClick="cmdAdd_Click" />
  6.             </HeaderTemplate>
  7.             <ItemTemplate>
  8.               <asp:Button ID="cmdSelect" runat="server" CausesValidation="False" CommandName="Select" Width="60" Text="Select" OnClick="cmdSelect_Click" />
  9.             </ItemTemplate>
  10.           </asp:TemplateField>
  11.           <asp:TemplateField ShowHeader="False">
  12.             <ItemTemplate>
  13.               <asp:Button ID="Button1" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" Width="60" OnClientClick="return confirm('Are you sure you want to delete this record?');" />
  14.             </ItemTemplate>
  15.           </asp:TemplateField>
  16.           <asp:BoundField DataField="StateID" HeaderText="StateID" InsertVisible="False" ReadOnly="True" SortExpression="StateID" Visible="False" />
  17.           <asp:BoundField DataField="StateDesc" HeaderText="State" SortExpression="StateDesc" />
  18.           <asp:BoundField DataField="StateAbr" HeaderText="Abbr" SortExpression="StateAbr" />
  19.           <asp:BoundField DataField="ParentDesc" HeaderText="Association" SortExpression="ParentDesc" />
  20.           <asp:CheckBoxField DataField="IsActive" HeaderText="Active?" SortExpression="IsActive" />
  21.         </Columns>
  22.       </asp:GridView>
  23.     <asp:ObjectDataSource ID="odsState" runat="server" DeleteMethod="Delete" OldValuesParameterFormatString="{0}" SelectMethod="GetData" TypeName="tblStateTableAdapters.usp_Sel_tblStateTableAdapter">
  24.       <DeleteParameters>
  25.         <asp:Parameter Name="StateID" Type="Int32" />
  26.       </DeleteParameters>
  27.       <SelectParameters>
  28.         <asp:Parameter Name="StateID" Type="Int32" />
  29.       </SelectParameters>
  30.     </asp:ObjectDataSource>
  31.  
Sep 14 '06 #3
Here are the two ObjectDataSources associated with the DetailsView script:

Expand|Select|Wrap|Line Numbers
  1.     <asp:ObjectDataSource ID="odsOneState" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="{0}" SelectMethod="GetData" TypeName="tblStateTableAdapters.usp_Sel_tblStateTableAdapter" UpdateMethod="Update">
  2.       <UpdateParameters>
  3.         <asp:Parameter Name="StateID" Type="Int32" />
  4.         <asp:Parameter Name="StateDesc" Type="String" />
  5.         <asp:Parameter Name="StateAbr" Type="String" />
  6.         <asp:Parameter Name="ParentID" Type="Int32" />
  7.         <asp:Parameter Name="IsStateChoice" Type="Boolean" />
  8.         <asp:Parameter Name="IsActive" Type="Boolean" />
  9.       </UpdateParameters>
  10.       <SelectParameters>
  11.         <asp:ControlParameter ControlID="GridView1" Name="StateID" PropertyName="SelectedValue" Type="Int32" />
  12.       </SelectParameters>
  13.       <InsertParameters>
  14.         <asp:Parameter Name="StateDesc" Type="String" />
  15.         <asp:Parameter Name="StateAbr" Type="String" />
  16.         <asp:Parameter Name="ParentID" Type="Int32" />
  17.         <asp:Parameter Name="IsStateChoice" Type="Boolean" />
  18.         <asp:Parameter Name="IsActive" Type="Boolean" />
  19.       </InsertParameters>
  20.     </asp:ObjectDataSource>
  21.  <asp:ObjectDataSource ID="odsActiveAssociations" runat="server" OldValuesParameterFormatString="original_{0}"
  22.     SelectMethod="GetData" TypeName="uspActiveAssociationsTableAdapters.usp_Sel_ActiveAssociationsTableAdapter">
  23.     <SelectParameters>
  24.       <asp:Parameter Name="StateID" Type="Int32" />
  25.     </SelectParameters>
  26.   </asp:ObjectDataSource>
Sep 14 '06 #4
It is the actual script for the DetailsView that I cannot seem to post although I have no image tags.
Sep 14 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Eamonn O'Connell | last post by:
Hi, We have an ASP.net application, where we dynamically add controls, in the Page_Load. Occasionally, when the user posts back the page (e.g. clicks Save button on the page), we get a "Failed...
0
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
1
by: et | last post by:
I. 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...
1
by: rockdale | last post by:
Sometime my ASP.NET application got this error message but not always everytime. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that...
6
by: sck10 | last post by:
Hello, I have applications that produce the following error when they have been open to long without activity. Is there any way to force a re-load of the page or go to another page if the page...
2
by: sck10 | last post by:
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...
0
by: nithagowda | last post by:
Hello, I have a DropDownList for source type and a panel for displaying TreeView based on the source type.. The problem is- if i select different source type drom ddlSrcType, other than the...
2
by: Rotsey | last post by:
Hi, I have a web site that uses user controls to display different formats of timesheets. I have a browse page that has prev/next buttons to browse through a set of timesheets. As I say...
3
by: sck10 | last post by:
Hello, I have a web project (VS 2008 c#). I have a page that opens, but when I try to call an assembly (managed c++) on a submit event, I get the following error on the web server, but not on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.