1.模態視窗的開啟,model window open
2.模態視窗的關閉,model window close
3.模態視窗的傳遞參數,model window get valuse
4.其他....,other ..
1.window.showModalDialog("DialogPage.aspx","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
2.window.close();
3.傳值
ParentPage.aspx:
window.showModalDialog("DialogPage.aspx?para1=aaa¶2=bbb");
DialogPage.aspx:
string str1=Request.QueryString["para1"].toString();
string str2=Request.QueryString["para2"].toString();
傳回值
DialogPage.aspx:
window.returnValue="aaa"; //返回aaa
ParentPage.aspx:
var str=window.showModalDialog("DialogPage.aspx"); //這樣可以得到模態視窗的傳回值aaa
在實際應用中可能如下:在DialogPage.aspx頁面中一按扭響應事件如下:
//確定事件處理常式
private void ibtnOK_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
DataTable dt=parameters.ParameterTable;
string name=parameters.STRTableName;
string strSearch="";
//返回拼接參數條件
strSearch=ReturnParaValues(dt);
if(strSearch!="")
{
strSearch=" and 1=1 "+strSearch;
}
//執行JavaScript指令碼
StringBuilder sb = new StringBuilder();
if (!this.Page.IsClientScriptBlockRegistered("GoExactSearchView"))
{
sb.Append("<script language='javascript'>\n")
.Append("window.returnValue =").Append("window.dialogArguments+\" "+strSearch).Append("\";\n")
.Append("window.close();\n")
.Append("</script>\n");
this.Page.RegisterClientScriptBlock("GoExactSearchView",sb.ToString());
}
}
上述程式運行時的一個樣本監視為:
strsearch = " and 1=1 and TempColumn63467 like '%CKD康明斯C300 20 (歐II)%'"
<script language='javascript'>
window.returnValue =window.dialogArguments+" and 1=1 and TempColumn63467 like '%CKD康明斯C300 20 (歐II)%'";
window.close();
</script>
<!--注意window.dialogArguments 的作用:在下面講到-->
這樣當單擊提交時,會將處理後的結果strSearch返回!並自動關閉該模態頁面!
而父頁面處理如下:
//以有模式開啟參數過濾視窗 馮岩 2007-04-23 e-works
function OpenParaListWin(Url,strArgs,CetValueCtlID)
{
document.getElementById("IframeSearch").src = Url;
document.getElementById("IframeSearch").style.display = "inline";
var resultValue=window.showModalDialog(Url,strArgs,'dialogWidth=500px;dialogHeight=500px;help:no;status:no; ');
/**//*注意其中第二個參數strArgs,其作用是在操作完開啟的模態視窗後,可以再將此參數返回給本頁面,如何擷取,即利用上面的window.dialogArguments屬性,即得到strArgs的值!這種方式有時比URL中傳參更好!不過window.dialogArguments只適用於mode和modeless視窗中*/
if(resultValue!=undefined)
{
//window.alert(resultValue);
document.getElementById(CetValueCtlID).value=resultValue;//處理模態視窗傳回值
document.getElementById('Form1').submit(); //自動認可本aspx頁面,以更新結果!
}
return false;
}
上述JS函數也是父視窗 單擊Button click的響應處理事件!如果返回有結果則會自動更新本頁面!
4.
aspx頁面在showmodeldialog情況下為什麼一提交就重新開啟一個頁面?
showmodaldialog開啟的頁面中在<head></head>之間加入一行:<base target="_self">