关于showModalDialog 的常见问题
在我們的實際開發中,經常會用到showModalDialog 模態窗體,對于其中的問題有時候真是讓人頭痛,在此我寫一點自己在開發中遇到的問題以及解決辦法。
一、刷新問題
第一種情況是:模態窗體的父窗體不刷新問題,就是在關閉模態窗口后,父窗體不刷新。
解決方法:在你的彈出模態窗體的JavaScript后面寫上window.location.reload();
第二種情況是:有時候不想讓父窗體刷新,也就是在關閉模態窗口后,讓父窗體不刷新
解決方法:在你的彈出模態窗體的JavaScript后面寫上return false;
二、關閉問題
關閉方法:使用JavaScript
window.opener=null;self.close();
三、傳遞對象
1protectedvoidbtnOK_Click(objectsender,EventArgse)
2{
3System.Text.StringBuildersb=newSystem.Text.StringBuilder();
4sb.Append("<scriptlanguage=\"javascript\">");
5stringstrReturnText=string.Empty;
6stringstrReturnValue=string.Empty;
7if(Request.Form["rbtnSelect"]!=null)
8{
9strReturnText=Request.Form["rbtnSelect"].ToString();
10strReturnValue=Request.Form["rbtnSelect"].ToString();
11//Response.Write(strReturnText);
12}
13if(rdo_NewLocation.Checked==true)
14{
15//strReturnText=Request.Form["rbtnSelect"].ToString();
16//strReturnValue=Request.Form["rbtnSelect"].ToString();
17
18sb.Append("varret=newObject();");
19sb.Append("ret.txt_BuildingName='"+txt_BuildingName.Text+"';");
20sb.Append("ret.txt_Unit='"+txt_Unit.Text+"';");
21sb.Append("ret.txt_Floor='"+txt_Floor.Text+"';");
22sb.Append("ret.txt_StreetNo='"+txt_StreetNo.Text+"';");
23sb.Append("ret.txt_Street='"+txt_Street.Text+"';");
24sb.Append("ret.txt_District='"+txt_District.Text+"';");
25sb.Append("ret.txt_City='"+txt_City.Text+"';");
26sb.Append("ret.txt_Country='"+txt_Country.Text+"';");
27
28}
29
30//sb.Append("window.returnValue='"+strReturnText+"|"+strReturnValue+"';");
31sb.Append("window.returnValue=ret;");
32sb.Append("window.close();");
33sb.Append("</script>");
34Response.Write(sb.ToString());
35}
36父頁面接收
<scriptlanguage="JavaScript"type="text/javascript">
functionRelocationSelect()
{
varret=window.showModalDialog("../Common/RelocationSelection.aspx",'','dialogWidth:630px;dialogHeight:300px;');
if(ret!=undefined)
{
document.getElementById("txt_BuildingName").value=ret.txt_BuildingName;
document.getElementById("txt_Unit").value=ret.txt_Unit;
document.getElementById("txt_Floor").value=ret.txt_Floor;
document.getElementById("txt_StreetNo").value=ret.txt_StreetNo;
document.getElementById("txt_Street").value=ret.txt_Street;
document.getElementById("txt_District").value=ret.txt_District;
document.getElementById("txt_City").value=ret.txt_City;
document.getElementById("txt_Country").value=ret.txt_Country;
}
returnfalse;
}
</script>
總結
以上是生活随笔為你收集整理的关于showModalDialog 的常见问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php怎么取随机3位数字,使用php怎么
- 下一篇: 搞懂ZooKeeper到底是做啥的