問題描述
我嘗試了多種解決方案來解決這個問題,但都沒有奏效.基本上,我有一張員工表,用戶可以選擇通過更新面板動態添加員工.每個員工都被添加為 LinkBut??ton,此按鈕將通過 ajaxToolkit:modalpopupextender 窗口>OnClick 事件,此窗口將顯示員工詳細信息.問題是當我點擊員工姓名時,彈出窗口會顯示但細節不會.
I’ve tried several solutions for this problem but none of them worked. Basically, I have a table of employees and the user have the choice of adding an employee dynamically thru an update panel. Each employee is being added as LinkButton and this button will fire ajaxToolkit:modalpopupextender window through OnClick event, and this window will show the employee details. The problem is when I click on the employee name the popup window will show up BUT the details wont.
這是我創建按鈕并將其放入表格的代碼:
Here is the code in which I’m creating the buttons and putting it in the table:
這里是employee_info方法:
and here is the employee_info method:
推薦答案
查看這個答案
https://stackoverflow.com/a/11127064/1268570
這解釋了動態控件的行為
This explains the behavior of dynamic controls
你需要考慮:
- 當您不使用母版頁時,應在 PreInit 事件中創建動態控件,如果是,則在 Init 事件中創建控件
- 避免在這些事件中設置可以在每個帖子中更改的屬性,因為當應用視圖狀態時(在帖子事件中),這些屬性將被覆蓋
- 每次發布??頁面時都必須創建動態控件,避免這種情況 if(!this.IsPostBack) this.CreatemyDynamicControls();
- 當您在 PreInit 或 Init 事件中創建控件時,它們的狀態將在 post 事件中自動設置,這意味著在 LoadComplete 事件中,即使您在每個 post 中再次創建控件,您的控件也會包含它們的狀態,甚至當您沒有明確設置它們的狀態時.請注意,當您處理在設計時創建的控件時,此行為是不同的,在這種情況下,設置狀態的事件是 Load 事件
- 事件訂閱應該在 PageLoadComplete 之前發生,否則它們將不會被引發
如果您還沒有找到解決方案,這是一種方法(完整的工作示例):
In case you have not found a solution, this is a way to do it (full working example):
代碼隱藏
輸出
這篇關于動態創建的 LinkBut??tons 的 OnClick 事件不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!