Click here to Skip to main content
15,916,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
question :- i want to create one dynamic button and want to write code in the property of this dynamic button?
my code is followes but it doesnt work:
C#
Button btn = new Button();
                btn.Text = "Add As Friend!";
                btn.ID = "Button1";
                                
                
                btn.Click += new System.EventHandler(btn_Click);
//
protected void btn_Click(object sender, EventArgs e)
       {

       }

error will comes int the following line:

C#
btn.Click += new System.EventHandler(btn_Click);


plz help me!

thanx in advance
Posted
Updated 31-Mar-12 16:14pm
v2
Comments
[no name] 31-Mar-12 22:13pm    
And that error would be? Out of the thousands of errors that it could possibly be, which one are you getting?
[no name] 31-Mar-12 23:05pm    
Wes is right! Paste here what error exactly you are getting
Lalit PB 2-Apr-12 6:13am    
I tried same code but it works fine with me.

Hi ,
it work fine with me .
C#
protected System.Web.UI.WebControls.Button btn;
protected void Page_Load(object sender, EventArgs e)
{
           btn = new Button();
            btn.Text = "Add As Friend!";
            btn.ID = "Button1";
            this.btn.Click += new System.EventHandler(btn_Click);
}
protected void btn_Click(object sender, EventArgs e)
{

}

Best Regards
M.Mitwalli
 
Share this answer
 
Formally, the code shown in this sample is correct. The problem is somewhere else, it could be in a method calling the method you are showing in a fragment, or your observation of the error is incorrect.

You really need to provide comprehensive information on errors and exceptions. "Does not work" is not informative and never used in issue reporting, if you want to work at least on a minimal professional level.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900