只是写一些例子,希望从中得到一些总结:
1.Open一个Dialog
string jsString1= "window.showModalDialog('" PageURL"+"', '','center: Yes; help: No; resizable:" + (isResizable ? "Yes" : "No") + "; status: No; dialogWidth:" + dialogWidth + "px; dialogHeight:" + dialogHeight + "px');";
string jsString2="if(result != null) { document.getElementById(\"ControlID1\").value = result;" +"document.getElementById(\"ControlID2\").value = result;}";
this.ControlID.OnClientClick = "var result=" + jsString1+jsString2;
这样就打开了一个简单的Dialog.注意这里是用onClientClick,故此仅是一些字符串就行了.
下面是演示ReturnValue---关闭窗口,直接返回.
string jsString="<script> function returnValue1(){ window.returnValue='" + stringVar+ "';window.close();} setTimeout('returnValue1()',5);</script>";
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", jsString);
注意这里用上了ClientScript.RegisterStartupScript.
2.提示信息后关闭-1.
page.ClientScript.RegisterStartupScript(page.GetType(), "Message" + MessageSeq, "<script>function MessageAndCloseWindow" + MessageSeq +"() { " +/"Open a Dialog to show Message (you can reference to the '1.Open一个Dialog' "/ + "window.close(); return false;} setTimeout('MessageAndCloseWindow" + MessageSeq + "()',5);</script>");
3.操作之前提前确认:
if (Page.Request.Form["__EVENTARGUMENT"].Equals(""))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "ConfirmMessage" + MessageSeq, "<script>function ConfirmMessage" + MessageSeq +
"() { var strMessageAction = " +/"Open a Dialog to show Message (you can reference to the '1.Open一个Dialog' "/ +
" if (strMessageAction == 'Confirm'){ " + ctrl.Page.ClientScript.GetPostBackEventReference(ctrl, "Confirm") +
"; } else { " + ctrl.Page.ClientScript.GetPostBackEventReference(ctrl, "Unconfirm") +
" ;} } setTimeout('ConfirmMessage" + MessageSeq + "()',5);</script>");
}
else if (Page.Request.Form["__EVENTARGUMENT"].Equals("Confirm"))
{
//Too ADD
}
注意这里open Dialog 要返回一个ReturnValue,同时被strMessageAction接收.注册GetPostBackEventReference(ctrl, "Confirm")
4.有时我们要postback一些信息.
ctrl.Page.ClientScript.RegisterStartupScript(ctrl.Page.GetType(), "Message" + MessageSeq, "<script>function MessageAndPostBack" +
MessageSeq + "() {" +/"Open a Dialog to show Message (you can reference to the '1.Open一个Dialog' "/ +
ctrl.Page.ClientScript.GetPostBackEventReference(ctrl, argument) + "; } setTimeout('MessageAndPostBack" + MessageSeq + "()',5);</script>");