2011-03-11 75 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對話框。

相關問題