asp.net dynamically button with event handler

前端 未结 1 939
渐次进展
渐次进展 2020-11-29 12:20

I have here a small problem with a dynamically generated buttons and their event handler in asp.net. I generate a flexible table with additional Buttons for special users. T

相关标签:
1条回答
  • 2020-11-29 12:49

    You must have to place that code in page_load or page_init event.

    protected void Page_Load()
    {
      Button ButtonChange = new Button();
    
      ButtonChange.Text = "Change";
      ButtonChange.ID = "change_" + i.ToString();
      ButtonChange.Font.Size = FontUnit.Point(7);
      ButtonChange.ControlStyle.CssClass = "button";
      ButtonChange.Click += new EventHandler(test);
    }
    

    Read MSDN article - How to: Add Controls to an ASP.NET Web Page Programmatically?

    0 讨论(0)
提交回复
热议问题