【发布时间】:2013-06-07 08:37:46
【问题描述】:
我有 3 个更新面板控制 asp.net,updatePanel1、updatePanel2、updatePanel3。第一次加载页面时updatePanel1 将自动加载更多buttons 例如:button1。当单击updatePanel1 中的button1 时,将显示updatePanel2 中的按钮,例如:button2。点击button2会触发updatePanel3,并像gridview一样在updatePanel3中显示数据。
现在,我的问题是当单击button2 updatePanel2 中的所有按钮时丢失。你能告诉我为什么我在updatePanel2 中丢失了按钮吗?
UPDATE
Default.cs
protected void Page_Load(object sender, EventArgs e) { foreach (KeyValuePair<String, String> catshow in cat) { Button x = new Button(); x.ID = catshow.Key; x.CssClass = "btnTop"; x.Text = catshow.Value; x.CommandArgument = catshow.Key; x.Command += new CommandEventHandler(buttonClick); PlaceHolder1.Controls.Add(x); } } protected void buttonClick(object sender, CommandEventArgs e) { string key = e.CommandArgument.ToString(); foreach (KeyValuePair<String, String> datshow in data[key]) { Button x = new Button(); x.ID = datshow.Key; x.CssClass = "btnBottom"; x.Text = datshow.Value; x.CommandArgument = datshow.Key; x.Command += new CommandEventHandler(buttonClickPrd); PlaceHolder2.Controls.Add(x); } } protected void buttonClickPrd(object sender, CommandEventArgs e) { string key = e.CommandArgument.ToString(); DataTable dt = new DataTable(); dt.Columns.Add("Qty", Type.GetType("System.String")); dt.Columns.Add("Unit", Type.GetType("System.String")); dt.Columns.Add("Price", Type.GetType("System.String")); dt.Columns.Add("Total", Type.GetType("System.String")); dt.Rows.Add(); dt.Rows[dt.Rows.Count - 1]["Qty"] = this.sales[key]["qty"]; dt.Rows[dt.Rows.Count - 1]["Unit"] = this.sales[key]["unit"]; dt.Rows[dt.Rows.Count - 1]["Price"] = this.sales[key]["price"]; dt.Rows[dt.Rows.Count - 1]["Total"] = this.sales[key]["total"]; GridView1.DataSource = dt; GridView1.DataBind(); }
Default.aspx
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
【问题讨论】: