[原创]由一个窗口打开另一个窗口向这个打开的窗口传值(要求第一个窗口不刷新页面)
有2种方法:
第一种是用cookie:
用到searchvalue和SetCookie两个js函数
第2种是Saucer大哥提供的:
由于一个页面不能有2个runat=server的Form
但可以多个非ruant=server的表单
加一个用于提交参数的Form
<form method="post" target="_blank" id="form2">
<input type="hidden" name="query">
</form>
通过search2函数实现参数传递
child.aspx页用如下代码来获得参数:
<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"><INPUT onclick ="search2();" style="Z-INDEX: 103; LEFT: 216px; POSITION: absolute; TOP: 144px" type="button"
value="Open by Saucer">
</form>
<form method="post" target="_blank" id="form2">
<input type="hidden" name="query">
</form>
</body>
<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"><INPUT onclick ="search2();" style="Z-INDEX: 103; LEFT: 216px; POSITION: absolute; TOP: 144px" type="button"
value="Open by Saucer">
</form>
<form method="post" target="_blank" id="form2">
<input type="hidden" name="query">
</form>
</body>
第一种是用cookie:
用到searchvalue和SetCookie两个js函数
<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;
}
function search2()
{
var sql="select * from companyjob";
document.all.form2.query.value=sql;
document.all.form2.action="child.aspx";
document.all.form2.submit();
}
</script>
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;
}
function search2()
{
var sql="select * from companyjob";
document.all.form2.query.value=sql;
document.all.form2.action="child.aspx";
document.all.form2.submit();
}
</script>
第2种是Saucer大哥提供的:
由于一个页面不能有2个runat=server的Form
但可以多个非ruant=server的表单
加一个用于提交参数的Form
<form method="post" target="_blank" id="form2">
<input type="hidden" name="query">
</form>
通过search2函数实现参数传递
child.aspx页用如下代码来获得参数:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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)
Response.Write("<br>Get value from The second Button:" + Request.Form("query"))
End If
End If
End Sub
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)
Response.Write("<br>Get value from The second Button:" + Request.Form("query"))
End If
End If
End Sub