How to assign functions or events to dynamic buttons in C# and Asp.net?

Viewed 49

I'm new to C#, however I started to work very well with it. The issue is that I am trying to create dynamic buttons and assign them a function (just for testing) this with the purpose that; at the end of the project, when the button is selected, do an insert into a SQL table with its properties as parameters. the code in question is:

protected void GenEx_Click(object sender, EventArgs e)
{
    Button newButton = new Button();
    newbutton.ID=option;
    //'response
    buttonNew.Text=Resc_Answer(name_tab, questionv2, option);        
    //HERE IS A PROBLEM
    newButton.Click += new System.EventHandler(this.addBtn_Click);                                       
    showExam.Controls.Add(newButton);
    showExam.Controls.Add(new LiteralControl("<br/>"));
}

// test function
private void addBtn_Click(Object sender,EventArgs e)
{
   string msg = "if it exits pro";
   ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert(" + msg + ");", true);
 }

up to this point, the web form works, the problem is that when you assign the event / function to it, it does not execute it. I have gone through the documentation and various forums without success. I thank you in advance

0 Answers
Related