HTML页面传值(asp.net)c#
2008-08-06 16:52
721 查看
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>
相关文章推荐
- C#(asp.net)根据静态模板生成静态(html)页面
- ASP.NET(C#)页面间传值的常见方法(转载)
- asp.net页面间传值的几种方法 表单提交 传送页面代码 复制代码 <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server
- ASP.NET C#动态生成html页面
- C# asp.net页面通过URL参数传值中文乱码问题解决办法
- C# asp.net页面通过URL参数传值中文乱码问题解决办法
- C# asp.net页面通过URL参数传值中文乱码问题解决办法
- asp.net(c#)生成静态html页面
- 记asp.net VB与C# 页面参数传值
- ASP.NET&C#学习笔录6(页面传值)
- ASP.NET(C#)页面间传值的常见方法
- 在C# ASP.NET中,要添加属性到控件中 在HTML页面获取控件中自己定义属性和值
- asp.net(c#)生成静态html页面
- asp.net页面之间传值的方式及C#中的索引器跟属性的区别
- asp.net 中为什么在showModalDialog弹出的窗体 用html 控件 刷新不了页面。而用服务器端控件 写C#代码可以刷新页面。但是用服务器端刷新页面不好。
- Asp.Net中的脚本回调和Server.Transfer页面传值http://www.zhuye123.com/Article/156/161/2006/2006042328785.html
- 将Asp.Net页面输出为HTML(c#)
- .Html+Asp+asp.net(C#)禁止浏览器缓存页面的方法-禁止缓存
- ASP.NET(C#)页面间传值的常见方法
- asp.net(c#)生成静态html页面