1

我有一个母版页:

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

我还有 3 个页面,带有导航按钮 Next 和 Back,如下所示:

<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>

请您告诉我,如何在不加载所有页面且仅重载内容的情况下在此页面之间导航?

4

1 回答 1

0

ContentPlaceHolderContent您可以在onbtnNextbtnBack OnClickevents中添加和删除控件

标记:

<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);
  }
于 2013-01-03T13:52:10.217 回答