Flow-of-control differences: declaratively creating controls vs dynamic

Last post 08-17-2005 11:51 AM by RobW. 0 replies.

Sort Posts:

  • Flow-of-control differences: declaratively creating controls vs dynamic

    08-17-2005, 11:51 AM
    • Member
      5 point Member
    • RobW
    • Member since 07-15-2005, 7:47 AM
    • Posts 1

    Hi, no code for this as it is rather long, and I wanted to see if anyone could help before I worked on a stripped down version!

    Basically, I'm creating a templated control for editing news items. The problem is that it works fine if I dynamically create the control on Page_Load, but not if I declare it as a server tag in the form.

    What it does is this:

    OnLoad: Loads news items from a predetermined database
    CreateChildControls: Creates controls for editing a single item, then for each item in database:
    - Creates edit / delete buttons, then instantiates a user supplied template to actually display these items.

    When, say, the delete button is clicked, it deletes that row from the database, reloads the dataset, then rebuilds the list of display items to reflect the now changed data.

    As I said, all working perfectly if the control is created dynamically.

    However, if it is declared as a server tag, although it looks okay the first time you load the page, on PostBack, the item buttons don't work.

    This is because now, CreateChildControls() is called BEFORE OnLoad(). This means that there is no datasource to build the list of items from, and so a) there is no list of items, and b) the edit / delete events don't fire because the controls for each item the events are attached to haven't been created.

    Now, the idea of this control is a drop in control with zero maintenance and code-behind on the pages which it is used - and obviously, as it is templated, I need it to be able to be created declaratively, so if anyone can help, I'd much appreciate it! It's been driving me insane as to why CreateChildControls is called before OnLoad! Thanks! Smile [:)]

    I suppose I could load the dataset in OnInit - but although I haven't been on any best practice training course, that just sounds wrong.

    Cheers, Rob.

     

     

Page 1 of 1 (1 items)