Dynamically Loaded User Controls

Discussion in 'ASP .Net Web Controls' started by Rich, Dec 15, 2005.

  1. Rich

    Rich Guest

    Hi,
    I have been looking into how dynamical user controls work on asp.net web
    pages.

    This simple code is used to load and add the control to the page, which also
    has a Label control.

    TextBox tb = new TextBox();
    this.Label1.Controls.Add(tb);

    This code has been tried in both the 'Page_Load' and the 'OnInit' events of
    the Page.

    (I also have a button on the page to test if viewstate is maintained after a
    postback.)
    If I add text to the control ( after the page is loaded) and then click the
    button to do a postback the text always stays the same.

    Can someone tell me why the viewstate is maintianed in both cases? I thought
    loading the control in the 'OnInit' event was the correct place to load
    controls and to maintian its viestate?

    Cheers
    Rich, Dec 15, 2005
    #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. Teo Lachev
    Replies:
    0
    Views:
    389
    Teo Lachev
    Jul 1, 2003
  2. Tim T
    Replies:
    7
    Views:
    508
    Adam Carden
    Nov 1, 2003
  3. Danny Bloodworth

    Events in dynamically loaded user controls

    Danny Bloodworth, Nov 20, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    539
  4. Josh
    Replies:
    1
    Views:
    9,520
    Jeffrey Palermo [MCP]
    May 26, 2004
  5. =?Utf-8?B?V291dGVy?=

    Dynamically Loaded controls loading other controls

    =?Utf-8?B?V291dGVy?=, Feb 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    488
    =?Utf-8?B?V291dGVy?=
    Feb 27, 2006
Loading...

Share This Page