使用UpdatePanel在contentplaceholder中的页面之间导航

时间:2013-01-03 11:17:35

标签: asp.net ajax updatepanel master-pages

我有一个主页:

<asp:UpdatePanel ID="upPanel" runat="server">
    <ContentTemplate>
         <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
         </asp:ContentPlaceHolder>
    </ContentTemplate>
</asp:UpdatePanel>

此外,我还有3个页面,其中包含导航按钮“下一步”和“后退”,如下所示:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
        <asp:Label ID="lbl1" runat="server">Second PAGE</asp:Label>
        <asp:Button ID="btnBack" runat="server" />
        <asp:Button ID="btnNext" runat="server" />
    </div>   
</asp:Content>

请问您,如何在不加载所有页面且仅加载内容的情况下在这些页面之间导航?

1 个答案:

答案 0 :(得分:0)

您可以在ContentPlaceHolderContentbtnNext btnBack次活动中OnClick添加和删除控件

<强>标记:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:UpdatePanel ID="upPanelContent" runat="server">
        <asp:contentplaceholder id="ContentPlaceHolderContent" runat="server" />
    </asp:UpdatePanel>  
    <asp:Button ID="btnBack" runat="server" OnClick="btnBack_Click"/>
    <asp:Button ID="btnNext" runat="server" OnClick="btnNext_Click"/>
</asp:Content>

<强>代码隐藏:

  protected btnNext_Click(Object sender, EventArgs e) 
  {
     ContentPlaceHolderContent.Controls.Clear();
     Literal l = new Literal();
     l.Text = "new content";
     ContentPlaceHolderContent.Controls.Add(l);
  }

  protected void btnBack_Click(Object sender, EventArgs e) 
  {
     ContentPlaceHolderContent.Controls.Clear();
     Literal l = new Literal();
     l.Text = "old content";
     ContentPlaceHolderContent.Controls.Add(l);
  }