Don't understand state in WebControls class

Discussion in 'ASP .Net Web Controls' started by kasterborus@yahoo.com, Aug 24, 2006.

  1. Guest

    I've been working on a web control class that generates a grid of
    checkboxes dynamically, based upon a DB query. I've been creating them
    in the Render method as needed.


    CheckBox _cb = new CheckBox();
    _cb.Text = "Assigned";
    _cb.RenderControl(tw);

    The only problem is of course any user interaction with the checkboxes
    is lost when posting back.

    I've tried adding them to the .Controls collection, setting
    EnableViewState to true, but nothing seems to work. The closest I've
    come to success is when I store the Checkboxes in the Viewstate
    explictly, but they are the "previous" checkboxes - no user interaction
    is recorded in them after postback.

    I know this has something to do with EnsureChildControls() and
    CreateChildControls() but all my attempts so far have failed.

    How do I tie a checkbox control (newly created or otherwise) to the
    state of the checkbox in the HTML, so that it contains any new user
    interaction?

    Thanks in advance!
     
    , Aug 24, 2006
    #1
    1. Advertising

  2. Teemu Keiski Guest

    They should be added to Controls collection in PreRender stage
    (Page_PreRender method or overridden OnPreRender method), so that state gets
    saved. Plus that they are dynamical controls, they would need to be
    recreated on postback.

    http://aspadvice.com/blogs/joteke/archive/2006/01/06/14568.aspx

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    <> wrote in message
    news:...
    > I've been working on a web control class that generates a grid of
    > checkboxes dynamically, based upon a DB query. I've been creating them
    > in the Render method as needed.
    >
    >
    > CheckBox _cb = new CheckBox();
    > _cb.Text = "Assigned";
    > _cb.RenderControl(tw);
    >
    > The only problem is of course any user interaction with the checkboxes
    > is lost when posting back.
    >
    > I've tried adding them to the .Controls collection, setting
    > EnableViewState to true, but nothing seems to work. The closest I've
    > come to success is when I store the Checkboxes in the Viewstate
    > explictly, but they are the "previous" checkboxes - no user interaction
    > is recorded in them after postback.
    >
    > I know this has something to do with EnsureChildControls() and
    > CreateChildControls() but all my attempts so far have failed.
    >
    > How do I tie a checkbox control (newly created or otherwise) to the
    > state of the checkbox in the HTML, so that it contains any new user
    > interaction?
    >
    > Thanks in advance!
    >
     
    Teemu Keiski, Aug 27, 2006
    #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. simon

    Error message I don't understand

    simon, Dec 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    321
    Hatim R
    Dec 5, 2003
  2. m miller

    don't understand error

    m miller, Jan 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,749
    smitdso
    Sep 8, 2006
  3. Wayne  Wengert

    Don't Understand

    Wayne Wengert, May 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    376
    Wayne Wengert
    May 1, 2004
  4. Grant Rettke
    Replies:
    0
    Views:
    453
    Grant Rettke
    Mar 16, 2005
  5. Martin P. Hellwig
    Replies:
    1
    Views:
    383
    Martin P. Hellwig
    Mar 26, 2010
Loading...

Share This Page