日期:2014-05-18  浏览次数:20436 次

在updatePanel外动态添加一些按钮,然后添加到tiger中,点击外部按钮的时候,点第一个正常,点第二个就刷新了整个页面,求赐教!!!
代码如下:后台
C# code
 /// <summary>
        /// 绑定列头
        /// </summary>
        private void Initial()
        {
            AggregateAnalyse.BLL.EM_B_MT dal = new AggregateAnalyse.BLL.EM_B_MT();
            DataTable dt = dal.GetBrName("84");
            if (dt == null || dt.Rows.Count < 1)
            { return; }
            int index = 1;
            int len = dt.Rows.Count;
            foreach (DataRow dr in dt.Rows)
            {
                HtmlGenericControl div = new HtmlGenericControl("div");
                div.ID = "mx" + index.ToString();
                if (index == 1)
                {
                    div.Attributes.Add("class", "menu_true");
                    this.hidFirstBrCode.Value = dr[0].ToString();
                }
                else
                {
                    div.Attributes.Add("class", "menu_false");
                }
                div.Attributes.Add("onclick", string.Format("SwitchAnything('mx','cx','menu_true','menu_false',{0},1,{1});", index, len));
                LinkButton btn = new LinkButton();
                btn.ID = "btnMtCode" + index.ToString();
                btn.Text = dr[1].ToString();
                btn.CssClass = "btnMenu";
                btn.Attributes.Add("Font-Underline", "false");

                btn.CommandName = dr[0].ToString();
                btn.Click += new EventHandler(this.BtnBrCode_Click);
                div.Controls.Add(btn);
                divMenu.Controls.Add(div);
                AsyncPostBackTrigger triger = new AsyncPostBackTrigger();
                triger.ControlID = btn.ID;
                triger.EventName = "Click";
                UpdatePanel1.Triggers.Add(triger);
                index++;
            }
        }



前台:
C# code
 <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div class="menu_frame" id="divMenu" runat="server">
    </div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <Triggers>
        </Triggers>
        <ContentTemplate>
            <div id="cx1" runat="server" class="content_true" style="width: 99%; height: 100%;
                overflow: auto;">
                <asp:HiddenField ID="hidFirstBrCode" runat="server" />
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="65%" valign="top" id="tdLeft" runat="server">
                            <asp:GridView ID="gvData1" runat="server" AutoGenerateColumns="False" CellPadding="5"
                                class="mGrid" Style="width: 80%; float: left; text-align: center;" OnRowDataBound="gvData1_RowDataBound">
                                <Columns>
                                    <asp:TemplateField HeaderText="序号" ShowHeader="False">
                                        <ItemTemplate>
                                            <%# Container.DataItemIndex + 1%>
                                        </ItemT