0

I created textbox and two button (Edit, Delete). I put some codes to add eventhandler per button.

for (int oo = 0; oo < mav.GetCategoriesSalary2(Emplvl.SelectedValue.ToString()).Rows.Count; oo++)
     {
         TextBox tb1 = new TextBox();
         tb1.ID = "textcat" + oo;
         tb1.Text = mav.GetCategoriesSalary2(Emplvl.SelectedValue.ToString()).Rows[oo][0].ToString();
         tb1.Width = 100;
         catresult.Controls.Add(tb1);

         Button newButton = new Button();
         newButton.ID = "btncatEdit" + oo;
         String aa = newButton.ID;
         newButton.Text = "Edit";
         catresult.Controls.Add(newButton);


         Button newButton1 = new Button();
         newButton1.ID = "btncatDelete" + oo;
         newButton1.Text = "Delete";
         catresult.Controls.Add(newButton1);
         newButton1.Click += new EventHandler(newButton1_Click);
    }

Here's the event.

void newButton1_Click(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + Emplvl.SelectedValue.ToString() + "');", true);
}

I run it. When I click the button the event is not working it just hide all textbox and button created within the for loop. What's wrong with my codes?

EnzoZow
  • 63
  • 1
  • 11

0 Answers0