Error with the event handlers of dynamic linkbutton

后端 未结 2 1121
旧巷少年郎
旧巷少年郎 2021-01-21 14:25

I am retrieving data from database depending upon the texboxes input and storing in a datatable , after then from datatable im sending data into dynamic table and displaying tab

相关标签:
2条回答
  • 2021-01-21 14:53

    You must have to use Page_Init or Page_Load event handler to write code that create controls dynamically. Please read MSDN pages on How to add controls dynamically and ASP.NET Page life cycle articles.

    0 讨论(0)
  • 2021-01-21 15:01

    You can add event handlers to the Page_Load event but the important think to remember is that they must be added on every page load. It is common to do setup type tasks such as this in a !Page.IsPostBack clause. When wiring up event handlers that's not the case otherwise they will seem to disappear

    if(!Page.PostBack)
    {
        control.EventRaised += new EventHandler(EventResponse)
    }
    

    is wrong and will result in the handler disappearing on postback

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