0

I add buttons dynamically.. e.g. Button newButton=new Button(); Now i want each button to be triggered. So i wrote them the following events:

    public void response_Click(object sender, EventArgs e)
{

}

public void edit_Click(object sender, EventArgs e)
{

}

public void quote_Click(object sender, EventArgs e)
{

}

  Button quote = new Button();
    Button reply = new Button();
    Button edit = new Button();

    quote.ID = "quote";
    reply.ID = "reply";
    edit.ID = "edit";

How do i trigger them, as soon as the user clicks on the button..will my functions above be triggered? do i need to do the following:

this.Clicked+=quote; this.Clicked+=reply; this.Clicked+=edit;

if i do need to do that..where do i put those lines of code?

i use visual studio 1010. asp.net

2 Answers 2

2

You can do like..

quote.Click += new EventHandler(quote_Click);
reply.Click += new EventHandler(response_Click);
edit.Click += new EventHandler(edit_Click);
Sign up to request clarification or add additional context in comments.

1 Comment

Or simply quote.Click += quote_Click, etc.
0

Yes, you would need to register the event of the button and associate it with particular method.

for example.

myButton.Click += new EventHandler(Button_Click);

void Button_Click(object sender, EventArgs e)
{
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.