Custom Composite Control, child User-controls loosing view state

Discussion in 'ASP .Net Building Controls' started by Mike J., Nov 24, 2003.

  1. Mike J.

    Mike J. Guest

    I've created composite custom control which dynamically creates and arranges
    it's child controls based on some xml data. Beside the simple web form
    controls there is an option of loading user-controls (UC) at run-time. Child
    controls are created/loaded/initialized in overridden CreateChildControls
    and then arranged in pages. Meaning - put in separate HtmlTables with only
    active one visible (property HtmlTable.Visible =
    is_this_page_the_active_one() set just before rendering).

    Now, everything works fine except the UC(s). UCs are loaded and displayed
    as they should be, their child-controls are "responsive" to the events, data
    entered is preserved across postbacks etc.

    Only after user switches to another page (UCs parent HtmlTable.Visible =
    false), and then switches back to the previous one is when UC and it's child
    controls loose their view state. All other "regular" controls preserve view
    states across page switching.

    This left me completely confused. UCs are loaded at exact time when all the
    other controls are created. They clearly preserve their view state across
    the postback. I made sure (through the debugger) that UCs view state is
    restored after switching to another page. It only gets lost after the switch
    back. There is no special initialization of UC's child controls.

    I've been struggling with this for days. Can someone please shed some light
    on this problem for me?
     
    Mike J., Nov 24, 2003
    #1
    1. Advertising

  2. "Mike J." <> wrote in message
    news:%...
    > I've created composite custom control which dynamically creates and

    arranges
    > it's child controls based on some xml data. Beside the simple web form
    > controls there is an option of loading user-controls (UC) at run-time.

    Child
    > controls are created/loaded/initialized in overridden CreateChildControls
    > and then arranged in pages. Meaning - put in separate HtmlTables with only
    > active one visible (property HtmlTable.Visible =
    > is_this_page_the_active_one() set just before rendering).
    >
    > Now, everything works fine except the UC(s). UCs are loaded and displayed
    > as they should be, their child-controls are "responsive" to the events,

    data
    > entered is preserved across postbacks etc.
    >
    > Only after user switches to another page (UCs parent HtmlTable.Visible =
    > false), and then switches back to the previous one is when UC and it's

    child
    > controls loose their view state. All other "regular" controls preserve

    view
    > states across page switching.
    >
    > This left me completely confused. UCs are loaded at exact time when all

    the
    > other controls are created. They clearly preserve their view state across
    > the postback. I made sure (through the debugger) that UCs view state is
    > restored after switching to another page. It only gets lost after the

    switch
    > back. There is no special initialization of UC's child controls.
    >
    > I've been struggling with this for days. Can someone please shed some

    light
    > on this problem for me?



    I suggest you don't use .Visible. .Visible determines whether the control
    renders at all, not whether it is visible or not.

    Instead, use:

    table.Style["display"] = "none";

    --
    John Saunders
    John.Saunders at SurfControl.com
     
    John Saunders, Nov 24, 2003
    #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. sleigh
    Replies:
    1
    Views:
    2,705
    sleigh
    Feb 12, 2004
  2. rodchar
    Replies:
    0
    Views:
    399
    rodchar
    Nov 26, 2007
  3. Buzz
    Replies:
    4
    Views:
    193
  4. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    322
    David Boike
    Aug 7, 2003
  5. Buddy Ackerman

    Accessing Child Controls in a composite custom control

    Buddy Ackerman, Dec 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    138
    Buddy Ackerman
    Dec 15, 2005
Loading...

Share This Page