Adding a Dynamic User Control from the Base Page Class (and retaining it on Postback?)

Discussion in 'ASP .Net Building Controls' started by David Bowey, Mar 10, 2005.

  1. David Bowey

    David Bowey Guest

    Hi There!

    As the subject says, I need to add a user control dynamically (using
    LoadControl function) to the derieved page from the base Page class and I
    want the added contol to be retained on PostBack as well as retain its'
    state (such as properties).

    How do I acoomplish this?

    Thank you all in advance.
    Dave
     
    David Bowey, Mar 10, 2005
    #1
    1. Advertisements

  2. David Bowey

    Guest

    If possible create the control in the OnInit each time. Make sure you
    give it a Unique ID. If you do both of these I believe the ViewState
    should be handled for you automatically
     
    , Mar 10, 2005
    #2
    1. Advertisements

  3. I think it is also pretty important that you add the control in to the
    controls collection before ammending any of its properties:

    i.e.
    dim txtAAA as textbox
    txtAAA = new textbox
    txtAAA.id = "txtAAA"
    txtAAA.text = "BBB" '<-- I don't think that this text property would be
    tracked by the viewstate
    me.controls.add(txtAAA)
    txtAAA.text = "AAA" <-- whereas this one would....




    "David Bowey" <> wrote in message
    news:%...
    > Hi There!
    >
    > As the subject says, I need to add a user control dynamically (using
    > LoadControl function) to the derieved page from the base Page class and I
    > want the added contol to be retained on PostBack as well as retain its'
    > state (such as properties).
    >
    > How do I acoomplish this?
    >
    > Thank you all in advance.
    > Dave
    >
    >
     
    Nick Stansbury, Apr 5, 2005
    #3
    1. Advertisements

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. Earl Teigrob
    Replies:
    0
    Views:
    535
    Earl Teigrob
    Aug 11, 2003
  2. Jeremy Jones
    Replies:
    4
    Views:
    1,501
    Jeremy Jones
    Dec 14, 2006
  3. Alf P. Steinbach
    Replies:
    6
    Views:
    823
    John Carson
    Sep 3, 2005
  4. mirin
    Replies:
    1
    Views:
    985
    Mark Rae [MVP]
    Mar 3, 2008
  5. Hicham Mouline
    Replies:
    1
    Views:
    841
    Victor Bazarov
    Apr 20, 2009
  6. Etrast

    Dynamic Template Column - retaining value on postback

    Etrast, Jun 17, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    422
    Tim_k
    Jun 30, 2004
  7. Etrast

    Dynamic Template Column - retaining value on postback

    Etrast, Jun 17, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    391
    Andy Z Smith
    Jun 17, 2004
  8. David Bowey
    Replies:
    2
    Views:
    293
    Nick Stansbury
    Apr 5, 2005
Loading...