①.master文件(母版页源代码)
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.style4
{
width: 249px;
}
.style5
{
width: 185px;
}
.style6
{
width: 156px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style6">
海贼团
</td>
<td class="style4">
图片
</td>
<td class="style5">
船员
</td>
<td>
经典语录
</td>
</tr>
<tr>
<td class="style6">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td class="style4">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
<td class="style5">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</td>
<td>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
②.master.cs文件(母版页后台代码)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void setName(String s)
{
Label1.Text = s;
}
public void add(String s)
{
ListBox1.Items.Add(s);
}
public void clearItem()
{
ListBox1.Items.Clear();
}
}
③.aspx文件(内容页源代码)
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/4E5CF69EF5137F5FD27B7AF668035844.png"
Height="154px" Width="247px" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="0">罗罗诺亚索隆</asp:ListItem>
<asp:ListItem Value="1">文斯莫克山治</asp:ListItem>
<asp:ListItem Value="2">GOD乌索普</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="确定" OnClick="Button1_Click" />
</asp:Content>
④.aspx.cs文件(内容页后台代码)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.setName("草帽海贼团");
}
protected void Button1_Click(object sender, EventArgs e)
{
String str = RadioButtonList1.SelectedValue;
switch (str)
{
case "0":
Master.clearItem();
Master.add("一个连船长都保护不了的人还谈什么野心。");
break;
case "1":
Master.clearItem();
Master.add("不要随随便便同情失败者,这会伤了他的自尊心。");
break;
case "2":
Master.clearItem();
Master.add("美女剑豪带着肉来了。");
break;
}
}
}
⑤效果图如图: