Failed to load viewstate when dynamically adding controls in placeholders

Discussion in 'ASP .Net' started by Sinisa Ruzin, Oct 7, 2004.

  1. Sinisa Ruzin

    Sinisa Ruzin Guest

    Hi all,
    I had problem with dynamically adding/removing controls;ascx,
    Controls.Add(Page.LoadControl... in the same page of the IBuySpy
    portal. ASP.NET, C#.
    I added buttons to the main ASCX loaded by desktopdefault.aspx. The
    buttons were used to "navigate" withing the same page. I had the
    problem with "fail to load viewstate ...." due to a mismatch controls
    in the treeview in the viewstate. Dynamically removing controls was
    messy and it did not work in some cases.
    I figured out that if I add an additional argument in the URL and
    assign the url to each of the buttons, then I effectively submit
    different urls each time I click any of the buttons despite the fact
    that I am still in "the same page(ascx).

    Example:

    Main URL to my page:
    http://localhost/VITRUAL_DIR/DesktopDefault.aspx?tabindex=4&tabid=19

    The buttons redirect to:
    http://localhost/VIRTUAL_DIR/DesktopDefault.aspx?tabindex=4&tabid=19&subtabid=1
    http://localhost/VIRTUAL_DIR/DesktopDefault.aspx?tabindex=4&tabid=19&subtabid=2
    and so on.
    I actually use subtabid to know where in the Page the user is, but if
    you don't need it, you can use a dummy parm every time you change your
    control list. I believe that the result will be tricking ASP engine
    into not using the Viewstate to reconstruct the control states, since
    the URL is now different;
    Example:
    http://localhost/VIRTUAL_DIR/DesktopDefault.aspx?tabindex=4&tabid=19&subtabid=Iadded2newControls

    http://localhost/VIRTUAL_DIR/Deskto...4&tabid=19&subtabid=IaddedSomeMorenewControls

    I'd like to hear comments on this workaround. I was trying to find a
    simple solution for quite few hours in the user groups, but nothing
    similar was suggested.
    Cheers,
    Sinisa Ruzin(contact aaAT itdesign-inc.com)
    http://www.itdesign-inc.com
    -- Custom Web Solutions--
     
    Sinisa Ruzin, Oct 7, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josh
    Replies:
    1
    Views:
    9,568
    Jeffrey Palermo [MCP]
    May 26, 2004
  2. sck10
    Replies:
    6
    Views:
    929
    sck10
    Sep 1, 2006
  3. tshad
    Replies:
    6
    Views:
    500
    tshad
    Aug 1, 2007
  4. Josh
    Replies:
    1
    Views:
    208
  5. Josh
    Replies:
    1
    Views:
    251
Loading...

Share This Page