tags:

views:

31

answers:

1

Hello

I'm trying to do the following: I have only a ScriptManager and an UpdatePanel (with empty ContentTemplate) on a page. I would like to add a button on it during the page load. Then after the button is pressed I would like to get an Ajax request and generate some dynamic controls on the page.

But it doesn't work, the code is below:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
        listServices();
}

private void listServices()
{
    Button button = new Button();
    button.Text = "Save";
    button.ID = "Save";
    button.Click += new EventHandler(button_Click);

    UpdatePanel1.ContentTemplateContainer.Controls.Clear();
    UpdatePanel1.ContentTemplateContainer.Controls.Add(button);

    AsyncPostBackTrigger trig = new AsyncPostBackTrigger();
    trig.ControlID = button.UniqueID;
    trig.EventName = "Click";
    UpdatePanel1.Triggers.Add(trig);
}

void button_Click(object sender, EventArgs e)
{
    throw new NotImplementedException();
}

I've looked into: [Adding controls dynamically to an UpdatePanel in ASP.NET AJAX][1] But it doesn't solve the problem in my case.

Doing this must be possible, many services have this functionality.

Thanks for help. Adam

A: 

Hai adam, Have a look at this one http://stackoverflow.com/questions/272928/how-can-i-create-buttons-and-hook-up-events-from-postback

It deals with commandEventHandler and you change it to event handler and it may work for you...

Pandiya Chendur