473,698 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Failed to Load Viewstate Error

10 New Member
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.C ontrol.LoadView StateRecursive( Objec t savedState) +355
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.C ontrol.LoadChil dViewStateByInd ex(Ar rayList childState) +142
System.Web.UI.C ontrol.LoadView StateRecursive( Objec t savedState) +303
System.Web.UI.P age.LoadAllStat e() +505
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +2543
Sep 14 '06 #1
4 5387
scottcly
10 New Member
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
scottcly
10 New Member
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
scottcly
10 New Member
Here are the two ObjectDataSourc es 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
scottcly
10 New Member
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
2989
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 to load viewstate" error. This happens on Windows Server 2003. It happens erratically, and appears to happen after the application has been running (and in use) for some time. When the problem arises, it appears to happen more frequently for a...
0
2571
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 usercontrol into the place holder... i dont know why im getting this error:
9
21642
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
1
6612
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 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. Description: An unhandled exception occurred during the execution of the current web...
1
2233
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 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
6
2931
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 has expired instead of getting the error? Thanks,
2
4493
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 Panel becomes visible. pnlGridViewSearchList pnlFormView The problem that I am having is that if I set the FormView Panel's
0
1651
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 item which was selected in the previous run the following error message is displayed.. Please help me in this regard.. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to...
2
11000
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 they can be different user controls for each timesheet type.
3
680
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 my development machine. It seems that this is the only dll in the Bin folder that has this problem. Any help with this would be appreciated. Thanks, sck10
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8867
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6522
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.