Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dynamic button btnQuestionNum and a integer i,
C#
btnQuestionNum= new Button();
btnQuestionNum.Text = Convert.ToString(i + 1);
btnQuestionNum.ID = i.ToString();
btnQuestionNum.Click += new EventHandler(btnDynamic);
placeholder.Controls.Add(btnQuestionNum);

I want to pass the value of i when button btnQuestionNum is clicked.
Posted
Comments
[no name] 10-Sep-13 7:29am    
Okay... why? Even if it were possible, it is unnecessary. The button clicked is the sender in your event handler.

1 solution

Try something like:
C#
btnQuestionNum.Click += (sender, e) => { MyHandler(sender, e, i); }; 

void MyHandler(object sender, EventArgs e, int i)
{
    //use int i here
}

I just show you an example how it could be done,hope you should understand what to do.
 
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