Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a dynamic button click event on a dynamic button?

I am creating one button on a page dynamically. Now I want to use the button click event on that button.

How can I do this in C# ASP.NET?

like image 552
AB Vyas Avatar asked May 31 '11 13:05

AB Vyas


People also ask

How can create button click event dynamically in asp net?

public form1() { foreach (Panel pl in Container. Components) { pl. Click += Panel_Click; } } private void Panel_Click(object sender, EventArgs e) { // Process the panel clicks here int index = Panels. FindIndex(a => a == sender); ... }

How to create a button Click event in c#?

Creating a C# Button To create a Button control, you simply drag and drop a Button control from Toolbox to Form in Visual Studio. After you drag and drop a Button to a Form, the Button looks like Figure 1. Once a Button is on the Form, you can move it around and resize it.

How do you create a dynamic button?

This example demonstrates how do I add a button dynamically in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.

How do you call a button click event?

How can I call SubGraphButton_Click(object sender, RoutedEventArgs args) from another method? private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }


1 Answers

Button button = new Button(); button.Click += (s,e) => { your code; }; //button.Click += new EventHandler(button_Click); container.Controls.Add(button);  //protected void button_Click (object sender, EventArgs e) { } 
like image 94
abatishchev Avatar answered Sep 29 '22 20:09

abatishchev