Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created dynamically button in a form.

But button event are not fired this application.
C#
Button btnContinue = new Button();
btnContinue.Attributes.Add("class", "button");
btnContinue.ID = "btnContinue";
btnContinue.Text = "Continue";
btnContinue.CausesValidation = false;
btnContinue.Click += new EventHandler(btnContinue_Click);                
form1.Controls.Add(btnContinue);

protected void btnContinue_Click(object sender, EventArgs e)
{
    ...
}

protected void Page_Init(object sender, EventArgs e)
{ 
    
}
Posted
Updated 6-Sep-12 19:25pm
v2

this is the example for required field validtor


RequiredFieldValidator reqif = new RequiredFieldValidator();
reqif.ID = "reqif";
reqif.ControlToValidate = txt2.ID;
reqif.ErrorMessage = "Enter no. flats";
pnlInfo.Controls.Add(reqif);
 
Share this answer
 
first you have to create a new instance of the button in the event
by the line

Button b = sender as Button;

now try to fire the event by the instance b.
 
Share this answer
 
Comments
kumar2233 7-Sep-12 1:42am    
i will try , But same problem arenot fired.

can u send sample code for this Dynamically Button Created....
Pradeep_kaushik 7-Sep-12 1:45am    
try when you creating event
btnContinue.Click += new System.EventHandler(btnContinue_Click);
kumar2233 7-Sep-12 1:49am    
This event i call u before i creating dynamically button.

Button btnContinue = new Button();
btnContinue.Attributes.Add("class", "button");
btnContinue.ID = "btnContinue";
btnContinue.Text = "Continue";
btnContinue.CausesValidation = false;
btnContinue.Click += new EventHandler(btnContinue_Click);
form1.Controls.Add(btnContinue);
Pradeep_kaushik 7-Sep-12 2:02am    
I do this and this works perfactly

Button btnSubmit = new Button();
btnSubmit.ID = "button";
btnSubmit.Text = "Submit ";
btnSubmit.Height = 80;
btnSubmit.Width = 80;
btnSubmit.Click += new System.EventHandler(btnSubmit_click);
pnlInfo.Controls.Add(btnSubmit);
kumar2233 7-Sep-12 2:35am    
i bind button control in form tag. same code i'm using y button event are not firing.

can u send code attachment link.or send gmailid[ maddulapradeep@gmail.com] ur code...

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