呼叫c#按鈕事件這是我的先例實現:如何從JQuery的對話框
在example.aspx:
<asp:Button ID="rejectButton" runat="server" Text="REJECT" OnClick="OnRejectButtonClick"/>
和example.aspx.cs:
protected void OnRejectButtonClick(object sender, EventArgs e)
{
// a lot of stuff...
rejecter();
}
...這工作。
現在我需要一個確認拒絕的對話框。現在我的代碼是:
在example.aspx:
<asp:Button ID="rejectButton" runat="server" Text="REJECT" OnClientClick="return openDialog();"/>
<div id="dialog" title="Seleziona causa">
<p>... bla bla...</p>
</div>
<script>
$(function() {
$("#dialog").dialog({ autoOpen: false, modal: true, show: "blind", hide: "blind",
buttons: {
"Okay": function() {
OnRejectButtonClick; // DOESN'T WORK!
$(this).dialog("close");
},
"Annulla": function() {
$(this).dialog("close");
}
}
});
});
function openDialog() {
$("#dialog").dialog("open");
return false;
}
</script>
和example.aspx.cs沒有改變。
但是在此更改之後,OnRejectButtonClick事件的調用不再觸發。我怎樣才能解決這個問題?
請注意,您需要在標籤上使用'ClientIDMode =「Static」'才能使其工作,因爲它是一個ASP標籤,並且在轉換爲HTML之前將生成ID,導致ID稍有不同。 –
@ChrisDavis是的,我忘了。 – mybirthname