主页面 Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="教学1._Default" %>
<!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>ASP.NET程序设计第一章</title>
<mce:script language="javascript" type="text/javascript"><!--
function Hi_onclick() {
var r=window.showModalDialog("inputMessage.aspx",{"name":"张三丰","age":88},"dialogWidth=16; dialogHeight=9;scroll=no; status=no;center=yes");
document.getElementById("Label1").innerHTML="你输入的信息是:<font color=red>姓名:</font>"+r.user+",<font color=red>年龄:</font>"+r.age;
}
// --></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server">单击按钮以输入信息</asp:Label><br /><br />
<input id="Hi" type="button"
value="显示模态对话框" onclick="Hi_onclick()" /><br />
</div>
</form>
</body>
</html>
模态对话框页面 inputMessage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="inputMessage.aspx.cs" Inherits="教学1.inputMessage" %>
<!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>
<mce:script language="javascript" type="text/javascript"><!--
// <!CDATA[
function Button1_onclick() {
window.returnValue={"user":document.getElementById('Text1').value,"age":document.getElementById('Text2').value};
window.close();
}
// --></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;" cellpadding="20">
<tr>
<td align="center">
姓名:<input id="Text1" type="text" /><br />
年龄:<input id="Text2" type="text" /><br />
<input id="Button1" type="button" value="完成输入" onclick="return Button1_onclick()" />
<mce:script type="text/javascript"><!--
var args=window.dialogArguments;
document.getElementById('Text1').value=args.name;
document.getElementById('Text2').value=args.age;
// --></mce:script>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
本文作者:记者 来源:CTOZJ
CIO之家 www.ciozj.com 微信公众号:imciow