如何在Updatepanel中添加用户控件

时间:2014-06-07 12:46:09

标签: asp.net ajax user-controls

我正在尝试在我的Ajax中加载UserControl但我不知道该怎么做。我的页面中有3个按钮,带有Ajax更新面板和3个UserControl。每次用户点击button1我想加载UserControl1,当用户点击button2时,我想加载UserControl2,依此类推。谁能告诉我怎么做到这一点?

<ul class="nav navbar-nav navbar-left">
    <li><a class="#123"><asp:Button ID="btnAddVideo" runat="server" Text="Add Tutorial" CssClass="VideoRoomMenu" OnClick="btnAddVideo_Click" /></a></li>
    <li><a class="#123"><asp:Button ID="btnEditVideo" runat="server" Text="Edit Video Details" CssClass="VideoRoomMenu" OnClick="btnEditVideo_Click" /></a></li>
    <li><a class="#123"><asp:Button ID="btnSearchVideo" runat="server" Text="Search Video" CssClass="VideoRoomMenu" OnClick="btnSearchVideo_Click" /></a></li>
</ul>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate></ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnAddVideo" EventName="btnAddVideo_Click" />
        <asp:AsyncPostBackTrigger ControlID="btnEditVideo" EventName="btnEditVideo_Click" />
        <asp:AsyncPostBackTrigger ControlID="BtnSearchVideo" EventName="btnSearchVideo_Click" />
    </Triggers>
</asp:UpdatePanel>

提前谢谢

2 个答案:

答案 0 :(得分:0)

下面提到不同UpdatePanel的不同控件的内容

<ul>
<li >
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <ContentTemplate>
             <a class="#123"><asp:Button ID="btnAddVideo" runat="server" Text="Add Tutorial" CssClass="VideoRoomMenu" OnClick="btnAddVideo_Click" /></a>
         </ContentTemplate>
         <Triggers>
             <asp:AsyncPostBackTrigger ControlID="btnAddVideo" EventName="Click" />
         </Triggers>
      </asp:UpdatePanel>
</li>
<li>
      <asp:UpdatePanel ID="UpdatePanel2" runat="server">
         <ContentTemplate>
             <a class="#123"><asp:Button ID="btnEditVideo" runat="server" Text="Edit Video Details" CssClass="VideoRoomMenu" OnClick="btnEditVideo_Click" /></a>
         </ContentTemplate>
         <Triggers>
             <asp:AsyncPostBackTrigger ControlID="btnEditVideo" EventName="Click" />
         </Triggers>
      </asp:UpdatePanel>
</li>
<li>
      <asp:UpdatePanel ID="UpdatePanel3" runat="server">
         <ContentTemplate>
             <a class="#123"><asp:Button ID="btnSearchVideo" runat="server" Text="Search Video" CssClass="VideoRoomMenu" OnClick="btnSearchVideo_Click" /></a>
         </ContentTemplate>
         <Triggers>
             <asp:AsyncPostBackTrigger ControlID="btnSearchVideo" EventName="Click" />
         </Triggers>
      </asp:UpdatePanel>
</li>
</ul>

答案 1 :(得分:0)

<ul>
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <ContentTemplate>
<li>
         <a class="#123"><asp:Button ID="btnAddVideo" runat="server" Text="Add Tutorial" CssClass="VideoRoomMenu" OnClick="btnAddVideo_Click" /></a>
</li>
<li>
         <a class="#123"><asp:Button ID="btnEditVideo" runat="server" Text="Edit Video Details" CssClass="VideoRoomMenu" OnClick="btnEditVideo_Click" /></a>
</li>
<li>
         <a class="#123"><asp:Button ID="btnSearchVideo" runat="server" Text="Search Video" CssClass="VideoRoomMenu" OnClick="btnSearchVideo_Click" /></a>
</li>

     </ContentTemplate>
     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="btnAddVideo" EventName="Click" />
         <asp:AsyncPostBackTrigger ControlID="btnEditVideo" EventName="Click" />
         <asp:AsyncPostBackTrigger ControlID="btnSearchVideo" EventName="Click" />
     </Triggers>
  </asp:UpdatePanel>
</ul>