2011-03-11 97 views
1

我是JQuery的新手,并尝试在用户单击aspx按钮时显示“是/否”确认对话框。当对话框显示给用户时,他可以点击是或否按钮,并根据用户的行动,我想执行不同的代码存在于代码后面的文件,即在aspx.cs如何在asp上显示Jquery对话框:按钮单击

我试着用下面的代码但没有成功实现我的目标。

代码出现在aspx页面:

<link href="jquery-ui-1.8.10.custom.css" rel="stylesheet" type="text/css" /> 
<script src="jquery-1.4.4.min.js" type="text/javascript"></script> 
<script src="jquery-ui-1.8.10.custom.min.js" type="text/javascript"></script> 

<script> 

    jQuery(document).ready(function() { 

     jQuery("#myButton").click(showDialog); 

     //variable to reference window 
     $myWindow = jQuery('#myDiv'); 

     //instantiate the dialog 
     $myWindow.dialog({ 
      autoOpen: false, 
      width: 400, 
      modal: true, 
      resizable: false, 
      buttons: { 
       "Yes": function() { 

       }, 
       "No": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 
    } 

    ); 
    //function to show dialog 
    var showDialog = function() { 
     //if the contents have been hidden with css, you need this 
     $myWindow.show(); 
     //open the dialog 
     $myWindow.dialog("open"); 
    } 

    //function to close dialog, probably called by a button in the dialog 
    var closeDialog = function() { 
     $myWindow.dialog("close"); 
    } 

</script> 

<form id="testconfirmJQ" name="testconfirmJQ" runat="server"> 
    <fieldset> 
    <legend>jQuery UI Modal Submit</legend> 
    <p><label for="email">E-mail:</label><br /> 
    <input id="emailJQ" type="text" name="emailJQ" value="" /></p> 
    <p> 
     <asp:Button ID="myButton" runat="server" Text="Button" onclick="myButton_Click" /> 
    </fieldset> 
    </form> 

    <div id="myDiv" title="Verify Form jQuery UI Style"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 0 0;"></span> You entered your e-mail address as:</p><p id="dialog-email"></p><p> 
    If this is correct, click Submit Form.</p><p>To edit, click Cancel.<p></div> 
</form> 

在事件处理程序的代码背后,现在是空的。任何建议将不胜感激!

+0

您遇到的问题是什么?当用户点击是或否时,您是否需要帮助创建特定帖子? – 2011-03-11 16:42:20

回答

1

取出asp:button的onclick属性。应该不需要它 - 你没有做服务器端操作。

你也可以将其更改为类型按钮的<input>

0

由于jQuery是客户端和你想在.aspx.cs文件来执行服务器端的代码,你可以尝试保存指出哪些用户响应提示的值和他们做一个回传,以便在服务器端可以执行适当的代码。

您可能会考虑使用Button.OnClientClick Property,它可以在回发之前执行客户端代码。仍然使用jQuery对话框。

相关问题