views:

67

answers:

3

this is my scenario:
i have a page with a placeholder. the page adds dynimcally different kinds of controls (we wan't to display some data - getting the id via querystring or postback, as we also have a tree) to this placeholder.
the added controls all, more or less, contain a textbox (name of the displaying element), checkbox (active-state of the displaying element) and a save-button which fires a method inside this webcontrol.

now my problem is really obvious: as i'm adding the control dynamically (and for every condition: !Postback and Postback), the save-method inside the so added control, won't fire - regardless what i do ...

i'm simply to stupid to get the trick :)

some behind-the-scene-infos (workflow):

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.Page.IsPostBack)
    {
        this.SelectedElement = SomeMagicMethod();
    }
}

protected void NodeSelected(object sender, TreeViewNodeEventArgs e)
{
    this.SelectedElement = SomeOtherMagicMethod();
}

protected override void OnLoadComplete(EventArgs e)
{
    // we have to take this life-cycle!
    if (this.SelectedElement!= null)
    {
        this.DisplayElement();
    }
}

private void DisplayElement()
{
    var UC = this.LoadControl(UCPath) as DataTypeUC;
    if (UC == null)
    {
     return;
    }

    UC.ID = EditCampaignFolderUCID;
    UC.SetData(this.SelectedElement);
    UC.DataBind();
    this.phContent.Controls.Add(UC);
}
A: 

While adding controls dynamically, you'll also have to wire up the event of the save button everytime (that is, if the save button is being generated dynamically).

Kirtan
save button is not dynamic, as it is part of the control! ??
Andreas Niedermair
A: 

Can you show the markup and code behind for the user control you are adding?

/Asger

asgerhallas
A: 

the trick is: reinstatiate everything in oninit, and in the order as the viewstate was saved at the last request ... tricky tricky

Andreas Niedermair