2013-03-26 52 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