Dynamically created Web User Control and ViewState problem

Discussion in 'ASP .Net Web Controls' started by A, Feb 26, 2005.

  1. A

    A Guest

    Hi everybody,

    I'm building a Web page in ASP.NET / C#.

    On that Web page, there is a button that when clicked will add a Web User
    Control (contains some labels, textboxes, radio buttons, and such). The user
    can click that button many times, each time adding one additional Web User
    Control. The user can also click another button to delete one of the Web
    User Control.

    The problem I'm having is that the ViewState data sometimes won't match with
    the correct Web User Control on postback (e.g. happens if I delete a middle
    Web User Control).

    I did some searching for the solution online, and I understand that the
    problem I'm having is normal because of the way the ViewState works. But I
    can't find the solution. I even tried to rename the IDs of all my controls
    within that Web User Control.

    I hope someone can point me in the right direction. Thanks.
    A, Feb 26, 2005
    #1
    1. Advertising

  2. A

    Wilco Bauwer Guest

    It is probably the best idea to keep track somewhere of the controls
    you need to display. Then you could databind that information against a
    databound control, each time you updated that information. A databound
    control like a Repeater will take care of ensuring that the controls
    are still in-tact after each postback.

    I have just posted a post related to dynamically created controls,
    since I see a lot of people struggling with problems related to that.
    You can read it at
    http://wilcoding.xs4all.nl/wilco/View.aspx?NewsID=147.

    ----
    http://wilcoding.xs4all.nl
    Wilco Bauwer, Feb 27, 2005
    #2
    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. John Crowley
    Replies:
    0
    Views:
    724
    John Crowley
    Jan 14, 2004
  2. yufufi
    Replies:
    2
    Views:
    385
    Teemu Keiski
    Jul 7, 2004
  3. Replies:
    5
    Views:
    724
  4. msimmons
    Replies:
    0
    Views:
    472
    msimmons
    Jul 16, 2009
  5. dickster
    Replies:
    0
    Views:
    225
    dickster
    Dec 8, 2005
Loading...

Share This Page