BehindCode 写 Javascript


只是写一些例子,希望从中得到一些总结:

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>");

优质内容筛选与推荐>>
1、文件系统的安装
2、3.5 视图
3、Python-logging日志模块
4、mysql最后一步总是未响应的解决办法
5、线性表顺序存储


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号