2013-09-10 55 views
13

我已經在網上進行了搜索,並嘗試了一些提供的解決方案,但沒有一個適合我。無法在jQuery對話框中點擊一個asp.net按鈕

我有一個div內的按鈕。我在jQuery對話框中顯示div。按鈕單擊不在jQuery對話框中工作。

我有我的代碼如下:

ASPX

<div id='one'> 
<asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton> 
</div> 
<div id="ViewModalPopupDiv2"> 
     <asp:UpdatePanel ID="UpdatePanel3" runat="server"> 
      <ContentTemplate> 
      <asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto"> 
      <asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click"/> 
      </asp:Panel> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
    </div> 

jQuery的

function ViewModelPopup2() { 
      $("#ViewModalPopupDiv2").dialog({ 
       scrollable: true, 
       width: 800, 
       modal: true 
      }); 
     } 

aspx.cs

protected void btnSendAlertEmail_Click(object sender, EventArgs e) 
     { 

      // Code to send email 

     } 

protected void btnConfigureAlerts_Click(object sender, EventArgs e) 
     { 

     ScriptManager.RegisterStartupScript 
         (this, this.GetType(), "callScriptFunction", "ViewModelPopup2();", true); 
     } 
    } 

請讓我知道我需要做的,觸發服務器控制ol事件。

+0

應該不是你的onClick事件有btnConfigureAlerts_Click()?爲什麼不只是使用正常的HTML按鈕,如果你只是要調用JavaScript函數? –

+0

我相信她想要從jQuery對話框中的按鈕後面觸發代碼。我認爲你的按鈕ID需要是「btnConfigureAlerts」。 – ElliotM

+0

檢查您的控制檯是否有javascript錯誤。 –

回答

22

我也有這個問題與asp.net按鈕和jQuery UI對話框。 要解決它,你需要在你的aspnet按鈕中設置標籤UseSubmitBehaviorfalse

如果UseSubmitBehavior屬性設置爲(這是默認值),該按鈕將使用瀏覽器的提交機制(和jQuery對話框的UI操作的話),如果UseSubmitBehavior設置爲,按鈕將使用asp.net框架在頁面中包含的客戶端腳本發佈到表單。

所以,你的HTML應該是這樣的:

<div id='one'> 
<asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton> 
</div> 
<div id="ViewModalPopupDiv2"> 
     <asp:UpdatePanel ID="UpdatePanel3" runat="server"> 
      <ContentTemplate> 
      <asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto"> 
      <asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click" UseSubmitBehavior="false" /> 
      </asp:Panel> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
    </div> 

更多細節在http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx

+0

我剛編輯我的代碼。請檢查它,我有兩個按鈕,我認爲我使用的按鈕單擊事件是正確的 – CodeNinja

+0

@ Agent007好的,我在答案中添加了一個示例。希望它能幫助你。 –

+0

嘿,謝謝這個作品!你能告訴我如何在jquery對話框中使用下拉列表嗎? DropdownList索引當前沒有更改。 – CodeNinja

4

這是經典的,感謝我的移動jQuery的對話,提問。

由於某種原因,jQuery UI會將您的對話框代碼移到窗體標記之外的html標記的底部。您需要在對話框搬回到形式更多的jQuery:

dlg.parent().appendTo(jQuery('form:first'));

其中DLG是您jQuery.UI對話框對象。

 var dlg = $("#ViewModalPopupDiv2").dialog({ 
      scrollable: true, 
      width: 800, 
      modal: true 
     }); 
     dlg.parent().appendTo(jQuery('form:first')); 

這應該讓你的工作再次爲你工作。乾杯!

如果不行,請嘗試這樣做,在打開的事件:

open: function(type,data) { $(this).parent().appendTo("form"); }

+0

嘿TombMedia!謝謝 !不知何故解決方案不起作用。我將上面的代碼封裝在一個名爲function ViewModalPopup2()的函數中。你認爲這會導致問題嗎? – CodeNinja

+0

沒有,那根本就不是問題。很高興看到你得到這個排序。 – TombMedia

+0

謝謝,它解決了我的問題:) – Tanu

相關問題