1.IframeRefresh.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IframeRefresh.aspx.cs"
Inherits="FunctionTest.IframeRefresh" %>
<!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 runat="server">
<title>无标题页</title>
</head>
<script type="text/javascript">
function Search()
{
var city=document.getElementById("txtCityName").value;
if(city!="")
{
document.getElementById("iframe1").src="MyFrame.aspx?city="+city;
}
}
</script>
<body>
<form id="form1" runat="server">
<div>
<center>
<table border="1">
<tr>
<td colspan="2">
<b>Iframe实现局部刷新</b>
</td>
</tr>
<tr>
<td>
城市名称:
</td>
<td>
<asp:TextBox ID="txtCityName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" name="btnQuery" value="查询" onclick="Search()" />
</td>
</tr>
<tr>
<td>
显示区域列表
</td>
<td>
<iframe src="MyFrame.aspx" style="text-align: center" id="iframe1" frameborder="0"
scrolling="no" height="30" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
2.MyFrame.aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyFrame.aspx.cs" Inherits="FunctionTest.MyFrame" %>
<!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlAreaList" runat="server" Width="100">
</asp:DropDownLis>
</div>
</form>
</body>
</html>
页面后台代码:
public partial class MyFrame : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//获取传递过来的参数
string city = Request.QueryString["city"];
switch (city)
{
case "北京":
ddlAreaList.Items.Clear();
ddlAreaList.Items.Add("朝阳");
ddlAreaList.Items.Add("海淀");
ddlAreaList.Items.Add("东城");
ddlAreaList.Items.Add("西城");
break;
case "上海":
ddlAreaList.Items.Clear();
ddlAreaList.Items.Add("浦东");
ddlAreaList.Items.Add("静安");
ddlAreaList.Items.Add("虹口");
ddlAreaList.Items.Add("徐汇");
break;
case "济南":
ddlAreaList.Items.Clear();
ddlAreaList.Items.Add("历下");
ddlAreaList.Items.Add("历城");
ddlAreaList.Items.Add("市中");
ddlAreaList.Items.Add("天桥");
break;
default:
break;
}
}
}