composite control and postback data change handling

Discussion in 'ASP .Net Building Controls' started by Donal McWeeney, Oct 12, 2004.

  1. Hi,

    I have a composite control that gets created dynamically and contains an
    array of checkbox controls and an array of drop down list controls.

    All the control postback and rendering works fine - however there is
    something that I want to do that I cant figure out how to do.

    In my OnLoad handler I was to examine the updated postback values and
    populate a new data structure based on these values. I need to do this
    before the postback events get raised.

    However because the control is created dynamically the postback data does
    not get set until the postback data second try event is ran - which is after
    the onload event.

    Is there a way to hook into this or is the only way to manually add changed
    events for each of the control items.

    Thanks

    Donal
     
    Donal McWeeney, Oct 12, 2004
    #1
    1. Advertising

  2. Hi Donal,

    From your description, you're developing a custom web server
    control(composite control) which will create all the sub controls(control
    tree) dynamically. And currently you're wondering how to get the new posted
    datas when the contorl is posted back and create new control tree structure
    depending on the new values, yes?
    If there're anything I didn't understanding correctly, please feel free to
    let me know.

    As for this problem, here are some of my suggestions:

    Generally, as for such a composite control which create control tree
    programmatically, I suggest that we put all the sub control's creation code
    in the "CreateChildControls" method, this method will be called before the
    Load event and also can be recalled in other events (no later than the
    PreRender event) so as to adjust the control tree.
    And for your problem, I think you can define some control properties which
    is persisted in VIEWSTATE which determine how to create the control's
    control tree(those sub controls) in the CreateChildControls method. Have
    your control implement "IPostBackDataHandler" interface? If so, you can
    try making use of the
    "bool IPostBackDataHandler.LoadPostData(string postDataKey,
    NameValueCollection postCollection)"
    interface , this event is fired after LoadViewState and Load , so we can
    get the new posted data collections in it and compare them with the old
    values in the VIEWSTAET, if different ,replace the properties with the new
    values. And you can recall the "CreateChildControls" method to restructure
    your control hierarchy when some of that properites are changed (in that
    property's accessor).

    In addition, here is a former thread in the group discussing on create a
    composite control which will adjust the control tree depending on the post
    back values:

    http://groups.google.com/groups?hl=zh-CN&lr=&threadm=#K2AUqGrEHA.2340@TK
    2MSFTNGP11.phx.gbl

    Hope helps. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 13, 2004
    #2
    1. Advertising

  3. Hi Steven,

    Thanks for the info.

    We dont implement the PostBackDataHandler interface in our composite control
    as the child controls we create like textboxes etc implement this and their
    values get set correctly on the postback.

    If I implement the PostBackDataHandler on my composite control will the
    child controls have performed postback processing at that stage? Or do I
    have to do something in code to get them to perform postback data
    processing?

    Thanks

    Donal





    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Donal,
    >
    > From your description, you're developing a custom web server
    > control(composite control) which will create all the sub controls(control
    > tree) dynamically. And currently you're wondering how to get the new
    > posted
    > datas when the contorl is posted back and create new control tree
    > structure
    > depending on the new values, yes?
    > If there're anything I didn't understanding correctly, please feel free to
    > let me know.
    >
    > As for this problem, here are some of my suggestions:
    >
    > Generally, as for such a composite control which create control tree
    > programmatically, I suggest that we put all the sub control's creation
    > code
    > in the "CreateChildControls" method, this method will be called before the
    > Load event and also can be recalled in other events (no later than the
    > PreRender event) so as to adjust the control tree.
    > And for your problem, I think you can define some control properties which
    > is persisted in VIEWSTATE which determine how to create the control's
    > control tree(those sub controls) in the CreateChildControls method. Have
    > your control implement "IPostBackDataHandler" interface? If so, you can
    > try making use of the
    > "bool IPostBackDataHandler.LoadPostData(string postDataKey,
    > NameValueCollection postCollection)"
    > interface , this event is fired after LoadViewState and Load , so we can
    > get the new posted data collections in it and compare them with the old
    > values in the VIEWSTAET, if different ,replace the properties with the new
    > values. And you can recall the "CreateChildControls" method to restructure
    > your control hierarchy when some of that properites are changed (in that
    > property's accessor).
    >
    > In addition, here is a former thread in the group discussing on create a
    > composite control which will adjust the control tree depending on the post
    > back values:
    >
    > http://groups.google.com/groups?hl=zh-CN&lr=&threadm=#K2AUqGrEHA.2340@TK
    > 2MSFTNGP11.phx.gbl
    >
    > Hope helps. Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
     
    Donal McWeeney, Oct 15, 2004
    #3
  4. Hi Donal,

    Thanks for the response. Yes, if we implement the PostBackDataHandler, we
    need to manually do the things to update the control's data properties ,
    also childrens. And after some further consideration, I think we don't
    actually need to implement that (which may make the problem more complex).

    Would you consider putting the post data handing in the post back events
    and recreate the sub controls structures at that time? I still thinnk
    that'll make the problem much easier.
    If you have any other ideas or any further question, please feel free to
    post here.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 18, 2004
    #4
  5. Hi Donal,

    Have you got any further progresses or ideas on this issue? If there're
    anything else we can help, please feel free to post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 26, 2004
    #5
  6. Hi Steven,

    I think I'm ok at the moment... will let you know if there is anything else.

    Thanks

    Donal
     
    Donal McWeeney, Oct 27, 2004
    #6
  7. Thanks for your followup Donal. Feel free to let me know if you have any
    further questions later in your work.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 28, 2004
    #7
    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,737
    sleigh
    Feb 12, 2004
  2. Aaron Prohaska

    sorting composite control data on postback

    Aaron Prohaska, Nov 6, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    163
    Aaron Prohaska
    Nov 6, 2003
  3. debartsa
    Replies:
    1
    Views:
    280
    John Saunders
    Apr 23, 2004
  4. Chad
    Replies:
    0
    Views:
    253
  5. STech

    Composite control, postback and change control tree

    STech, Nov 4, 2005, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    537
    Steven Cheng[MSFT]
    Nov 21, 2005
Loading...

Share This Page