Viewstate Error
-
Hi, I have form with 3 tabs, i each one i have a grid. My problem is - sometimes i'm getting this error when i'm pressing the EDIT button.
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.
At the first time nothing happens, but at the second click i'm getting the above error Can someone please please help me? Thanks; Tamir Here is an example of one of the grids (i post only one column):<asp:GridView ID="GridViewTransTab" runat="server" ShowFooter="True" AutoGenerateColumns="False"
DataKeyNames="fName,main,startHour,endHour" OnDataBinding="GridViewTransTab_DataBinding"
OnRowDataBound="GridViewTransTab_RowDataBound" OnRowCreated="GridViewTransTab_OnRowCreated"
OnRowCancelingEdit="GridViewTransTab_RowCancelingEdit" OnRowCommand="GridViewTransTab_RowCommand"
OnRowEditing="GridViewTransTab_RowEditing" OnRowUpdating="GridViewTransTab_RowUpdating"
BackColor="#00CCFF" BorderWidth="2px" Font-Names="Arial" Font-Size="12pt" OnRowDeleting="GridViewTransTab_RowDeleting"
EnableViewState="true">
<RowStyle BorderWidth="2px" />
<Columns>
<asp:TemplateField HeaderText="Full Name">
<EditItemTemplate>
<asp:DropDownList ID="txtFullNameTrans" runat="server" DataTextField="FullName" DataValueField="PersonId">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtFullNameNewTrans" runat="server" DataTextField="FullName" DataValueField="PersonId">
</asp:DropDownList>
</FooterTemplate> -
Hi, I have form with 3 tabs, i each one i have a grid. My problem is - sometimes i'm getting this error when i'm pressing the EDIT button.
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.
At the first time nothing happens, but at the second click i'm getting the above error Can someone please please help me? Thanks; Tamir Here is an example of one of the grids (i post only one column):<asp:GridView ID="GridViewTransTab" runat="server" ShowFooter="True" AutoGenerateColumns="False"
DataKeyNames="fName,main,startHour,endHour" OnDataBinding="GridViewTransTab_DataBinding"
OnRowDataBound="GridViewTransTab_RowDataBound" OnRowCreated="GridViewTransTab_OnRowCreated"
OnRowCancelingEdit="GridViewTransTab_RowCancelingEdit" OnRowCommand="GridViewTransTab_RowCommand"
OnRowEditing="GridViewTransTab_RowEditing" OnRowUpdating="GridViewTransTab_RowUpdating"
BackColor="#00CCFF" BorderWidth="2px" Font-Names="Arial" Font-Size="12pt" OnRowDeleting="GridViewTransTab_RowDeleting"
EnableViewState="true">
<RowStyle BorderWidth="2px" />
<Columns>
<asp:TemplateField HeaderText="Full Name">
<EditItemTemplate>
<asp:DropDownList ID="txtFullNameTrans" runat="server" DataTextField="FullName" DataValueField="PersonId">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtFullNameNewTrans" runat="server" DataTextField="FullName" DataValueField="PersonId">
</asp:DropDownList>
</FooterTemplate>Can you add the code behind, if you are adding a control dynamically (something like
Controls.Add(myControl);
), not doing this at postback is the most likely cause of your error (as the exception states). -
Can you add the code behind, if you are adding a control dynamically (something like
Controls.Add(myControl);
), not doing this at postback is the most likely cause of your error (as the exception states).Keith Barrow wrote:
if you are adding a control dynamically (something like Controls.Add(myControl);), not doing this at postback is the most likely cause of your error (as the exception states).
I'm not using this command.
Controls.Add(myControl);
Keith Barrow wrote:
Can you add the code behind
My code is very very long, i don't think it's smart to post it here.
-
Hi, I have form with 3 tabs, i each one i have a grid. My problem is - sometimes i'm getting this error when i'm pressing the EDIT button.
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.
At the first time nothing happens, but at the second click i'm getting the above error Can someone please please help me? Thanks; Tamir Here is an example of one of the grids (i post only one column):<asp:GridView ID="GridViewTransTab" runat="server" ShowFooter="True" AutoGenerateColumns="False"
DataKeyNames="fName,main,startHour,endHour" OnDataBinding="GridViewTransTab_DataBinding"
OnRowDataBound="GridViewTransTab_RowDataBound" OnRowCreated="GridViewTransTab_OnRowCreated"
OnRowCancelingEdit="GridViewTransTab_RowCancelingEdit" OnRowCommand="GridViewTransTab_RowCommand"
OnRowEditing="GridViewTransTab_RowEditing" OnRowUpdating="GridViewTransTab_RowUpdating"
BackColor="#00CCFF" BorderWidth="2px" Font-Names="Arial" Font-Size="12pt" OnRowDeleting="GridViewTransTab_RowDeleting"
EnableViewState="true">
<RowStyle BorderWidth="2px" />
<Columns>
<asp:TemplateField HeaderText="Full Name">
<EditItemTemplate>
<asp:DropDownList ID="txtFullNameTrans" runat="server" DataTextField="FullName" DataValueField="PersonId">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtFullNameNewTrans" runat="server" DataTextField="FullName" DataValueField="PersonId">
</asp:DropDownList>
</FooterTemplate> -
This is considered rude. See the FAQs and guidance stickies at the top of the forum. I've told you what the problem probably is (dynamically added controls), and asked for the code. I am 80% certain you are adding a control in code-behind that is being accessed in postback before it is getting re-added, but without the code it is impossible to tell.