欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

如何传值在2个页面之间 要求不刷新父页面,并且不能用Querystring传值

程序员文章站 2023-11-14 17:22:40
例子: 以下是父页的html代码 <%@ page language="vb" autoeventwireup="false" codebehind="main.as...
例子:
以下是父页的html代码
<%@ page language="vb" autoeventwireup="false" codebehind="main.aspx.vb" inherits="zero.main"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>main</title>
<meta name="generator" content="microsoft visual studio .net 7.1">
<meta name="code_language" content="visual basic .net 7.1">
<meta name="vs_defaultclientscript" content="javascript">
<meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" charset="gb2312">
function searchvalue()
{
var sql="select * from companyjob";
setcookie("sendsql",sql);
var url="child.aspx";
window.open(url,'_blank');
}
function setcookie(name, value)
{
document.cookie = name + "=" + value;
}
</script>
</head>
<body ms_positioning="gridlayout" >
<form id="form1" method="post" runat="server">
<input id="hidden1" style="z-index: 101; left: 8px; position: absolute; top: 8px" type="hidden"
name="hidden1" runat="server"><input style="z-index: 102; left: 96px; position: absolute; top: 144px" type="button" onclick="searchvalue();"
value="open" id="button1" name="button1">
<asp:button id="button2" style="z-index: 103; left: 256px; position: absolute; top: 152px" runat="server"
text="button"></asp:button>
</form>
</body>
</html>
child 页[子页]
<%@ page language="vb" autoeventwireup="false" codebehind="child.aspx.vb" inherits="zero.child"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>child</title>
<meta name="generator" content="microsoft visual studio .net 7.1">
<meta name="code_language" content="visual basic .net 7.1">
<meta name="vs_defaultclientscript" content="javascript">
<meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language =javascript >
function getv()
{
alert(document.forms("hidden1"));
document.all("hidden1").value=document.forms("hidden1");
}
</script>
</head>
<body ms_positioning="gridlayout" >
<form id="form1" method="post" runat="server">
<input style="z-index: 101; left: 8px; position: absolute; top: 8px" type="hidden" id="hidden1"
name="hidden1" runat="server"></font>
</form>
</body>
</html>
.vb文件
if not ispostback then
'response.write(request.form("hidden1"))
dim cookie as httpcookie = request.cookies("sendsql")
if not cookie is nothing then
response.write(cookie.value)
end if
end if
2。是思归大哥介绍的方法
在父页中加入一个非runat=server的form表单,用来提交隐藏控件的值到子页
<form method="post" target="_blank" id="form2">
<input type=hidden name="query">
</form>
<script language="javascript">
function searchvalue()
{
var sql="select * from companyjob";
document.all.form2.query.value=sql;
document.all.form2.action="child.aspx";
document.all.form2.submit();
}
</script>
子页的后台代码中 (.vb)
在page_load事件中写
response.write(request.form("query"))