2013-03-26 24 views
0

我想從onClick後面的代碼中打開對話窗口。如何運行腳本?從後面的代碼運行JQuery對話窗口

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css" /> 
    <div id="dialog" title="Alert!!!" style="display: none;"> 
     <p> 
      Lorem Ipsum 
     </p> 
    </div> 

     private void InitializeComponent() 
     { 
      this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click); 
      this.Load += new System.EventHandler(this.Page_Load); 
     } 

     private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e) 
     { 
      //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "$(function() {$('#dialog').dialog('open');});", true); 
     } 
+0

我試着寫onClickScript到一個按鈕。在這種方法中,我可以輕鬆打開對話框。但在服務器中,它不起作用。現在,我想在後面的代碼中打開對話框。 – baros 2013-03-26 13:43:05

+0

@Nix該項目被寫入.Net 2.0。我無法調試代碼。我不知道錯誤是什麼。 – baros 2013-03-26 13:43:48

+0

不知道爲什麼你需要爲此使用代碼。您是否嘗試過使用'asp:Button'控件的'onClientClick'屬性並將您的客戶端腳本放在那裏,或者使用JS函數調用來打開一個對話框? – Floremin 2013-03-26 14:33:40

回答

1

試試這個

ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script> $('#dialog').dialog('open');return false; </script>"); 
+1

其System.Web.UI並使用頁面對象,如果您使用的是ajax,則使用ScriptManager.RegisterClientScriptBlock – Lingaraj 2013-03-26 16:42:02