动态加载页面中的多个页面

时间:2012-10-14 22:19:13

标签: asp.net c#-4.0

我有一个用c#,ASP.NET编写的网站。我想根据左侧菜单中的链接动态加载右侧div中的页面。但我不知道从哪里开始,哪个控制等等。 请帮帮我..

enter image description here

3 个答案:

答案 0 :(得分:1)

使用右侧的iframe标记来包含动态加载的页面,然后在右侧的链接的target属性中指定iframe的name属性。

<table>
 <tr>
   <td>
     <a href='www.reddit.com/r/jquery' target='contentFrame'>first Link</a> <br/>
     <a href='www.reddit.com/r/javascript' target='contentFrame'>Second Link</a>
   </td>
   <td>
               <iframe name='contentFrame' />
   </td>


    </tr>
</table>

答案 1 :(得分:0)

有多种方法可以做到这一点。一种简单的方法是使用CSS创建布局(即左侧菜单,右侧内容)和MasterpageMasterpage是一个页面,是其他页面在具有共同点时可以使用的模板。在这里,左侧的菜单对于您的所有页面都是通用的,因此您可以在主页面中创建该布局。每个页面(例如firstpage.aspx)都会继承该主页,您只需填写右侧的内容即可。

有许多CSS资源,但this site可能会帮助您开始使用布局方面。有关主页的更多信息可以在here找到。

替代方法包括使用AJAX动态加载页面。根据您的设计,这可能有点棘手。

答案 2 :(得分:0)

使用MasterPage和ContentPages

示例:

母版

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="GlobalMaster.master.cs" Inherits="your masterpage class" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="menupanel">
    </div>
    <div id="mainpanel">
       <asp:ContentPlaceHolder ID="mainPlaceHolder" runat="server" />
    </div>
</body>
</html>

ContentPage

<%@ Page Title="" Language="C#" MasterPageFile="~/path to your masterfile.Master" AutoEventWireup="true" CodeBehind="page code behind" Inherits="page class" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainPlaceHolder" runat="server">
    <h3>
        Your cool content here
    </h3>
</asp:Content>

注意如何使用Page指令中的以下属性定义要使用的MasterPage:

<%@ Page MasterPageFile="~/path to your masterfile.Master" 

当您定义这样的页面时,它们被称为内容页面

要在Content控件中定义内容

<asp:Content ID="Content1" ContentPlaceHolderID="mainPlaceHolder" runat="server">

另请注意名称在MasterPage的{​​{1}} ID和ContentPlaceHolder的{​​{1}}属性

之间的匹配方式
相关问题