UpdatePanel内的LinkBut​​ton触发完整回发

时间:2013-07-04 12:18:09

标签: asp.net asp.net-ajax updatepanel linkbutton

我在使用部分回发在更新面板中动态添加控件时遇到问题。我在代码后面动态生成一些LinkBut​​ton并设置它们的触发器,但是当我触发它们时它们完全回发,甚至LinkBut​​ton事件也不会被调用我解雇他们。他们被放在'divPageNumber'

* ASPX:

</asp:DataList>
               <table style="width: 100%">
                   <tr style="width: 10%">
                       <td>
                           <asp:LinkButton ID="lnkPrevious" runat="server" Font-Bold="True"
                               NavigateUrl="~/Default.aspx" OnClick="lnkPrevious_Click" Width="100px">&lt;&lt;صفحه قبل</asp:LinkButton>
                       </td>
                       <td style="width: 80%">
                           <div id="divPageNumber" dir="rtl" runat="server">
                           </div>
                       </td>
                       <td style="width: 10%">
                           <asp:LinkButton ID="lnkNext" runat="server" Font-Bold="True"
                               NavigateUrl="~/Default.aspx" OnClick="lnkNext_Click" Width="80px">صفحه بعد&gt;&gt;</asp:LinkButton>
                       </td>
                   </tr>
               </table>
           </ContentTemplate>
           <Triggers>
               <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Command"></asp:AsyncPostBackTrigger>
               <asp:AsyncPostBackTrigger ControlID="LinkButton2" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton3" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton4" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton5" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton6" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton7" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton0" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="btnSearchHead" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="LinkButton8" EventName="Command" />
               <asp:AsyncPostBackTrigger ControlID="lnkNext" EventName="Click" />
               <asp:AsyncPostBackTrigger ControlID="lnkPrevious" EventName="Click" />                   
           </Triggers>

       </asp:UpdatePanel>

和* .cs:

LinkButton btnPage;
            for (int i = 1; i <= objPagedDataSource.PageCount; i++)
            {
                btnPage = new LinkButton();                    
                btnPage.ID = "btnPage" + i.ToString();                    
                if (i == GetCurrentPageNumber + 1)
                    btnPage.Font.Bold = true;
                btnPage.Width = 10;
                btnPage.Style["margin-right"] = "2px";
                btnPage.Style["margin-left"] = "2px";
                btnPage.Text = i.ToString();

                if (brand != "" && brand != null)
                    btnPage.PostBackUrl = "Default.aspx?brand=" + brand + "&Page=" + i.ToString();
                else if (model != "" && model != null)
                    btnPage.PostBackUrl = "Default.aspx?model=" + model + "&Page=" + i.ToString();
                else
                    btnPage.PostBackUrl = "Default.aspx?Page=" + i.ToString();

                divPageNumber.Controls.Add(btnPage);

                LinkButton lb = (LinkButton)divPageNumber.FindControl("btnPage" + i.ToString());
                lb.Click += new EventHandler(lnkdel_OnClick);

                //Creates a new async trigger
                AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
                trigger.ControlID = lb.UniqueID;
                trigger.EventName = "Click";
                UpdatePanel1.Triggers.Add(trigger);

                ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
            }
            UpdatePanel1.Update();

protected void lnkdel_OnClick(object sender, EventArgs e)
    {

    }
    protected void lnkPrevious_Click(object sender, EventArgs e)
    {
        //GetCurrentPageNumber -= 1;
        //BindDataToRepeter();
        Response.Redirect("Default.aspx?Page=" + (Convert.ToInt32(Page.Request["Page"]) - 1).ToString());
    }
    protected void lnkNext_Click(object sender, EventArgs e)
    {
        //GetCurrentPageNumber += 1;
        //BindDataToRepeter();

        Response.Redirect("Default.aspx?Page=" + (Convert.ToInt32(Page.Request["Page"]) + 1).ToString());
    }

'lnkNext'和'lnkPrevious'是静态添加和工作。但'lnkdel_OnClick'不起作用。

我在做什么?

感谢

1 个答案:

答案 0 :(得分:1)

我从这个帖子中解决了我的问题

http://forums.asp.net/t/1895457.aspx/1