Professional Web Applications Themes

Viewstate error on second postback to page - ASP.NET General

I have a page that uses a custom object I wrote to build a table. I also have a post back to the page to remove items from that table. When the page loads I can see the viewstate code on the source of the page is about 5 lines. When I post back to remove an item and rebuild the page it works. I view the source of the page and the viewstate code has doubled in size even though I have less data for it to hold. On the second post back I get "The viewstate is invalid ...

  1. #1

    Default Viewstate error on second postback to page

    I have a page that uses a custom object I wrote to build a table. I also
    have a post back to the page to remove items from that table. When the page
    loads I can see the viewstate code on the source of the page is about 5
    lines. When I post back to remove an item and rebuild the page it works. I
    view the source of the page and the viewstate code has doubled in size even
    though I have less data for it to hold. On the second post back I get "The
    viewstate is invalid for this page and might be corrupted."

    I get this error even if I turn off view state for the table that is being
    rebuilt. Any thoughts on what is happening? I can provide more detail if
    needed. Also, this code is running locally on my PC. There is no issue
    with the transfer between webservers.




    Chris Guest

  2. #2

    Default Re: Viewstate error on second postback to page

    "Chris Thompson" <com> wrote in message
    news:phx.gbl... 
    page 

    even 
    "The 
    if 

    Chris, if you turn on page tracing, you'll find that it will show you the
    control hierarchy, along with the viewstate size each control is
    contributing.

    This sort of thing happens when the control hierarchy changes between
    postbacks. At the beginning of a subsequent request, you first want to
    reconstruct the same control hierarchy which existed at the end of the
    previous request. This control hierarchy can then consume the same ViewState
    which it created at the end of the previous request. Only then can you
    change the control hierarchy by adding or removing controls.

    This changed hierarchy can then produce viewstate. At the beginning of the
    next request, you'll rebuild the control hierarchy as it was at the end of
    this request ...
    --
    John Saunders
    Internet Engineer
    com


    John Guest

  3. #3

    Default Re: Viewstate error on second postback to page

    Hi,

    Thanks for the reply. I'm a little confused on the control hierarchy.
    How is it that I can control/change this between requests?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Chris Guest

  4. #4

    Default Re: Viewstate error on second postback to page

    "Chris Thompson" <com> wrote in message
    news:phx.gbl... 

    The term "Control hierarchy" (or better, "Control Tree") refers to which
    controls contain which other controls in their "Controls" collection. It can
    be changed by doing things like dynamically adding or removing controls.
    --
    John Saunders
    Internet Engineer
    com


    John Guest

Similar Threads

  1. Persisting DataSource on Postback using ViewState
    By Chris Carter in forum ASP.NET
    Replies: 4
    Last Post: March 7th, 12:50 PM
  2. Dropdownlist not keeping viewstate after postback
    By David Wyn Davies in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: May 30th, 12:37 PM
  3. DataGrid empty on Postback with ViewState enabled
    By news.acsalaska.net in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 3rd, 05:50 AM
  4. Replies: 0
    Last Post: May 24th, 09:17 AM
  5. Replies: 0
    Last Post: August 11th, 04:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139