Sunday, February 23, 2014

How to remove all children of panel in update panel

Hello everyone.


I has a problem.. In pageload event i create dynamic textbox and add to panel (pn_control).. When i click button i want to remove textbox and add new dropdowlist into pn_control. I use update panel, it don't work but when i remove update panel in code design, it work..


So.. how can i remove all children of panel using updatepanel?


Here is my code.





<table style="width: 100%;">
<tr>
<td align="right" style="padding-right: 10px;">
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="cmd_ViewReport" runat="server" Width="90" Text="Xem báo cáo" OnClick="cmd_ViewReport_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</td>

<tr>
<td>
<asp:UpdatePanel ID="udp_Control" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pn_Control" runat="server" Style="width: 100%; padding: 5px 5px;">
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmd_ViewReport" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>

CS:



protected void cmd_ViewReport_Click(object sender, EventArgs e)
{
pn_Control.Controls.Clear();
DropDownList ddl = new DropDownList() { ID = "ddl_Demo", Width = 150 };
pn_Control.Controls.Add(ddl);
}


No comments:

Post a Comment