【发布时间】:2012-04-02 17:19:11
【问题描述】:
我有许多服务器端生成的超链接
<a id="ctl00_ContentPlaceHolder1_APMySlides_unlinkImage_2428_1" title="Click Here to remove this image from this application." class="APMySlides_unlinkImage" href="#"></a>
<a id="ctl00_ContentPlaceHolder1_APMySlides_unlinkImage_2428_2" title="Click Here to remove this image from this application." class="APMySlides_unlinkImage" href="#"></a>
<a id="ctl00_ContentPlaceHolder1_APMySlides_unlinkImage_2428_3" title="Click Here to remove this image from this application." class="APMySlides_unlinkImage" href="#"></a>
<a id="ctl00_ContentPlaceHolder1_APMySlides_unlinkImage_2424_3" title="Click Here to remove this image from this application." class="APMySlides_unlinkImage" href="#"></a>
触发更新的部分
<asp:HiddenField ID="delhiddenfield" runat="server" />
<asp:Button ID="lauchdelete" runat="server" Text="" OnClick="removeLink" CssClass="lauchdelete" style="display:none;" />
<div id="deleteconfirm" title="Are you sure?" style="display:none;">Are you sure you want to remove this image from this application?</div>
一点点的 JQuery 会在任何被点击时调用另一个函数
var del = '<%=delhiddenfield.ClientID %>';
$(function(){
$('.APMySlides_unlinkImage').click(function (event) { triggerdel(event); });
});
function triggerdel(event) {
var caller = event.target || event.srcElement;
// get the id vals
var idsplit = caller.id.split("_");
if (idsplit.length > 2) {
$('#' + del).val(idsplit[idsplit.length - 2] + "_" + idsplit[idsplit.length - 1]);
$("#deleteconfirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Delete": function () {
// this section is supposed to trigger the update
$('.lauchdelete').click();
$('#' + del).val('');
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
}
如果我将 OnClientClick="alert('woo lauchdelete clicked')" 放入launchdelete 按钮,它会触发,但我后面的代码不会调用。但是,如果我像这样取出模态对话框:
function triggerdel(event) {
var caller = event.target || event.srcElement;
// get the id vals
var idsplit = caller.id.split("_");
if (idsplit.length > 2) {
$('#' + del).val(idsplit[idsplit.length - 2] + "_" + idsplit[idsplit.length - 1]);
$('.lauchdelete').click();
$('#' + del).val('');
}
}
代码正常运行,并触发后面的代码。我能看到的唯一区别是对话框控件,但为什么呢?有什么方法可以让控件按预期触发,按下模态对话框删除按钮?
【问题讨论】:
标签: c# jquery asp.net jquery-ui updatepanel