您的位置:首页 > Web前端 > HTML

HTML页面传值(asp.net)c#

2008-08-06 16:52 696 查看

HTML页面传值(asp.net)c#

有时候在页面中打开一个窗口后,还需要得到打开窗口的返回值,这里有个例子。按以下步骤进行:
进入Vs:
1。新建项目PgeTransferValue
2。新建三个web页面:
一:TestTransferValue.aspx
二:TestShowModalDialog.aspx
三:TestOpen.aspx
3。三个文件的html代码如下:
TestTransferValue.aspx
<%@ Page language="c#" Codebehind="TestTransferValue.aspx.cs" AutoEventWireup="false" Inherits="PgeTransferValue.TestTransferValue" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test TransferValue</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script>
function TestShowModalDialog()
{
var rv=window.showModalDialog("TestShowModalDialog.aspx",window,"dialogWidth=400px;dialogHeight= 300px");
var txtReturnValue=document.getElementById("txtReturnValue");
if (rv==undefined)
{
txtReturnValue.value="没有返回值";
}
else
{
txtReturnValue.value=rv;
}
}
function TestOpen()
{
window.open("TestOpen.aspx","_blank","height=300,width=400");
}
</script>
</HEAD>
<body>
<form id="frmTestTransferValue" method="post" runat="server">
<INPUT id="txtReturnValue" type="text" name="txtReturnValue"><br>
<INPUT onclick="TestShowModalDialog();" type="button" value="用window.showModalDialog()方法"><br>
<INPUT onclick="TestOpen();" type="button" value="用window.open()方法"><br>
</body>
</HTML>

TestShowModalDialog.aspx

<%@ Page language="c#" Codebehind="TestShowModalDialog.aspx.cs" AutoEventWireup="false" Inherits="PgeTransferValue.TestShowModalDialog" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test ShowModalDialog</title >
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=http://schemas.microsoft.com/intellisense/ie5>
<script>
function CreateReturnValue()
{
var txtReturnValue=document.getElementById("txtReturnValue");
if (txtReturnValue.value=="")
{
window.alert("请输入返回值");
return ;
}
returnValue=txtReturnValue.value;
window.close();
}
</script>
</HEAD>
<body>
<form id="frmTestShowModalDialog" method="post" runat = "server">
返回值:<INPUT type="text" id="txtReturnValue" name = "txtReturnValue">
<INPUT type="button" value="关闭页面并返回输入的值" onclick = "CreateReturnValue();">
</form>
</body>
</HTML>

TestOpen.aspx

<%@ Page language="c#" Codebehind="TestOpen.aspx.cs" AutoEventWireup="false" Inherits="PgeTransferValue.TestOpen" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test Open</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function CreateReturnValue(closeWindow)
{
var txtReturnValue=document.getElementById("txtReturnValue");
if (txtReturnValue.value=="")
{
window.alert("请输入传递值");
return ;
}
var txtOpenerReturnValue=window.opener.document.getElementById("txtReturnValue");
txtOpenerReturnValue.value=txtReturnValue.value;
window.alert("值已经传给父窗体");
if (closeWindow)
{
window.opener=null;
window.close();
}
}
</script>
</HEAD>
<body>
<form id="frmTestOpen" method="post" runat="server">
返回值:<INPUT type="text" id="txtReturnValue" name="txtReturnValue"> <INPUT type="button" value="不关闭页面并返回输入的值" onclick="CreateReturnValue(false);"><br>
<INPUT type="button" value="关闭页面并返回输入的值" onclick="CreateReturnValue(true);">
</form>
</body>
</HTML>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: