February 16, 2012

Code To create event handler at run time on button click in asp.net using c#

Code To create event handler at run time on button click in asp.net using c#

 using System;  
 using System.Configuration;  
 using System.Data;  
 using System.Linq;  
 using System.Web;  
 using System.Web.Security;  
 using System.Web.UI;  
 using System.Web.UI.HtmlControls;  
 using System.Web.UI.WebControls;  
 using System.Web.UI.WebControls.WebParts;  
 using System.Xml.Linq;  
 public partial class _Default : System.Web.UI.Page  
 {  
 protected void Page_Load(object sender, EventArgs e)  
 {  
 Button btn2 = new Button();  
 form1.Controls.Add(btn2);  
 btn2.Text = "Example1";  
 btn2.Click += new EventHandler(btn2_Click);  
 }  
 void btn2_Click(object sender, EventArgs e)  
 {  
 Response.Write("Gooooooogle");  
 }  
 }