Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Viewstate Error

Viewstate Error

Scheduled Pinned Locked Moved ASP.NET
helpcsssysadmindata-structuresregex
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treuveni
    wrote on last edited by
    #1

    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>

    K T 2 Replies Last reply
    0
    • T treuveni

      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>

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      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).

      Sort of a cross between Lawrence of Arabia and Dilbert.[^]

      T 1 Reply Last reply
      0
      • K Keith Barrow

        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).

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]

        T Offline
        T Offline
        treuveni
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T treuveni

          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>

          T Offline
          T Offline
          treuveni
          wrote on last edited by
          #4

          Can someone please help me with this problem? I'm stuck

          K 1 Reply Last reply
          0
          • T treuveni

            Can someone please help me with this problem? I'm stuck

            K Offline
            K Offline
            Keith Barrow
            wrote on last edited by
            #5

            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.

            Sort of a cross between Lawrence of Arabia and Dilbert.[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups