event is not raising for the dynamic button

Posted by Snvrk1985 under ASP.NET on 7/27/2012 | Points: 10 | Views : 940 | Status : [Member] | Replies : 1
i have created a dynamic button under listbox selectedindex change.
i have written the code for the click. the event is not raising. here is my code.


if (Controllist.SelectedValue == "Button")
{
if (Page.IsPostBack)
{
Button btn = new Button();
ContentPanel.Controls.Add(btn);
btn.ID = "dynbtn";
btn.Text = "Dynamic Button";
btn.Height = 30;
btn.Width = 70;
btn.Click += new EventHandler(btnclick);
}

}

protected void btnclick(object sender, System.EventArgs e)
{
TextBox txt = new TextBox();
ContentPanel.Controls.Add(txt);
txt.Height = 30;
txt.Width = 100;
txt.Text="This is Dynamic Text Box";
}




Responses

Posted by: Vforvijay on: 7/27/2012 [Member] Starter | Points: 25

Up
0
Down
hi..
Refer the link to call event for dynamic created button..

http://www.dotnetcode.in/2011/09/create-link-button-at-runtime-in-aspnet.html


Snvrk1985, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response