BehindCode 寫 Javascript

來源:互聯網
上載者:User

只是寫一些例子,希望從中得到一些總結:

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

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.