且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新面板不会动态创建动态创建的按钮单击事件控件

更新时间:2023-09-10 14:19:16

我自己已经解决了。谢谢所有人对于您的宝贵意见。



注意:在动态面板创建或动态控制创建期间,尝试为每个控件生成唯一ID,即使在删除控件/面板之后也是如此。 / BLOCKQUOTE>

On dynamically created control button click event working and refreshing data on 1st button click but on multiple button click event in Panel inside dynamic panel after 1st button click update panel not refreshing dynamically created panel on delete.

<asp:UpdatePanel ID="updateitem" runat="server" UpdateMode="Conditional">


Inside panel i am creating dynamic control and inside dynamic control again dynamic control.When i am trying to delete created control inside panel through below method and i want to delete each Child panel on button click.

for better understanding follow the below example:

<asp:Panel Id="Panel1" runat="Server"> this is actual panel in design page

<asp:Panel Id="PanelD1" runat="Server"> this is dynamic created panel in code behind

<asp:Panel Id="PanelD1Child1" runat="Server"> 

this is dynamic child panel of PanelD1 in code behind 

</asp:Panel>

<asp:Panel Id="PanelD1Child2" runat="Server"> 

this is dynamic child panel of PanelD1 in code behind

</asp:Panel>

</asp:Panel>

</asp:Panel>



if (DynamicPanel.Controls.Contains(CustPanel))
{
  DynamicPanel.Controls.Remove(CustPanel);
  CustPanel.Dispose();
  updateitem.Update();
}



It works for 1st button click inside dynamically created panel but when i click another button inside same panel it follow the above method and removes control but UpdatePanel is not refreshing Panel that's why page is showing the same controls after delete button click.

I have solved it myself.Thanks to all for your valuable comments.

Note: During dynamic panel creation or dynamic control creation try to generate unique id for each and every control even after deletion of controls/Panel.