父窗口弹出子窗口的 button处理事件:
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script language=javascript>window.open('WebForm1.aspx','', 'alwaysRaised=1,dependent=1,resizable=0,scrollbars,width=450,height=550');</script>");
}
父窗口html代码添加如下javascript代码
<script language="javascript">
function refresh()
{
this.location = this.location;
}
</script>
子窗口关闭窗口的 button处理事件:
private void Button1_Click(object sender, System.EventArgs e)
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append("<script language = javascript>");
scriptString.Append("window.opener.refresh();");
scriptString.Append( " window.focus();" );
scriptString.Append( " window.opener=null;" );
scriptString.Append( " window.close(); " );
scriptString.Append("</"+"script>");
Response.Write(scriptString.ToString());
// Response.Write("<script language=javascript>window.close()</script>");
}
现在用asp.net2.0,要实现一个功能:a页面点击一个按钮,弹出一个窗口,选择数据,然后数据返回到a页面的某个textbox里面。
以前我用
if(!IsClientScriptBlockRegistered("clientScript2"))
{
string strScript2= "<script>function OpenWin2(){var str=window.showModalDialog('user.aspx',document.Form1.sx.value,'dialogWidth:455px; dialogHeight:450px;');document.Form1.sx.value=str}</script>";
RegisterClientScriptBlock("clientScript2", strScript2);
}
nw.Attributes.Add("onclick", "OpenWin()");
这样去做,不知道还有其他更好的方法吗?
用window.open也可以,在弹出窗口中调用父窗口的js函数,实现传值:opener.someFunction("someValue");