how to fire event at run time
-
Hi, all I have a Button is being created at run time. Like for(i=0;i<10;i++) { Button btn = new Button(); btn.id= "btn" + i; btn.click = new Handler(btn_click); panel1.controls.add(btn); } And the Event Handler is: ----------------------- protected void btn_click(sender, EventArgs ) { Response.write("Clicked"); } My problem is that handler is not fired. If I am putting the above code in Page_load then it is working. I there any way to come out. Please help me Thanks to all
-
Hi, all I have a Button is being created at run time. Like for(i=0;i<10;i++) { Button btn = new Button(); btn.id= "btn" + i; btn.click = new Handler(btn_click); panel1.controls.add(btn); } And the Event Handler is: ----------------------- protected void btn_click(sender, EventArgs ) { Response.write("Clicked"); } My problem is that handler is not fired. If I am putting the above code in Page_load then it is working. I there any way to come out. Please help me Thanks to all
Hi sapan... Try this code
Pgae Load..
{
Button btn = new Button();
btn.ID = "btn" + i;
btn.Click += new EventHandler(btn_Click);
panel1.Controls.Add(btn);
} //End Page Load
protected void btn_Click(object sender, EventArgs e)
{
Response.Write("Clicked");
}Regards Hari
-
Hi sapan... Try this code
Pgae Load..
{
Button btn = new Button();
btn.ID = "btn" + i;
btn.Click += new EventHandler(btn_Click);
panel1.Controls.Add(btn);
} //End Page Load
protected void btn_Click(object sender, EventArgs e)
{
Response.Write("Clicked");
}Regards Hari
hi hari, Actually that I know but my scenario is I have created many buttons on a particular event. Then later on when the buttons are generated. I have to click on that and event handlers should work according that. Actually in each post back page lost its contents is there any way to retain objects of page as well as event handlers associated with them. Thanks Sapan
-
hi hari, Actually that I know but my scenario is I have created many buttons on a particular event. Then later on when the buttons are generated. I have to click on that and event handlers should work according that. Actually in each post back page lost its contents is there any way to retain objects of page as well as event handlers associated with them. Thanks Sapan