In my asp.net page codebehind,I am creating a button dynamically and adding a event handler to it.But when i set a breakpoint on the button click event(which i added in codebehind),its not hitting.Any idea why ?
My code is here
ASP.NET PAGE
<form runat="Server" id="frm1">
<div id="divPaymentOptions" runat="Server"> </div>
</form>
CODEBEHIND (C#)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadControl();
}
}
private void LoadControl()
{
Button objTempBtn = new Button();
objTempBtn.ID = "myDynamicBtn";
objTempBtn.Text = "Clich me";
objTempBtn.Click+=new EventHandler(objTempBtn_Click);
this.divPaymentOptions.Controls.Add(objTempBtn);
}
private void objTempBtn_Click(object sender, EventArgs e)
{
string strMsg="want to do something here";
}
I put a breakpoint on divPaymentOptions.But that didnt hit when i ran it.But the postback happens when i click the button.It comes to the PageLoad method.No idea why its not coming to my button click event.
Any ideas ? Thanks in advance.