我正在尝试在单击DataList控件中的LinkButton时使用jQuery-UI确认对话框,但我尝试过的任何内容似乎都无法正常工作。 DataList是数据库条目的文件附件列表。
这是原始.aspx文件的相关部分:
<ul id="attachmentList">
<asp:DataList ID="dlAttachments" runat="server" DataKeyField="AttachID" RepeatLayout="Flow">
<ItemTemplate>
<li>
<asp:HyperLink ID="hlViewAttach" runat="server" NavigateUrl='<%# CreateAttachURL(Convert.ToInt32(Eval("AttachID"))) %>'
Text='<%# Eval("Description").ToString() %>' Target="_blank" />
<em>(</em><asp:Label ID="lblType" runat="server" Text='<%# GetFriendlyFileType(Eval("FileType").ToString()) %>' Font-Italic="True"></asp:Label>,
<asp:Label ID="lblSize" runat="server" Text='<%# GetFriendlyFileSize(Convert.ToInt32(Eval("FileSize"))) %>' Font-Italic="True"></asp:Label><em>)</em>
<asp:LinkButton ID="btnDelAttach" runat="server" OnClick="btnDelAttach_Click"
OnClientClick="return ConfirmDeleteAttachment(this, 'Please confirm deletion', 'Are you sure you wish to delete this attachment?');">DELETE</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</ul>
以下是ASP.Net生成的上述HTML:
<ul id="attachmentList">
<span id="ctl00_mainContent_wizNewIPR_dlAttachments">
<li><a id="ctl00_mainContent_wizNewIPR_dlAttachments_ctl00_hlViewAttach" href="ViewAttachment.aspx?AttachID=260" target="_blank">Attachment description #1</a>
<em>(</em><span id="ctl00_mainContent_wizNewIPR_dlAttachments_ctl00_lblType" style="font-style:italic;">Acrobat PDF document</span>,
<span id="ctl00_mainContent_wizNewIPR_dlAttachments_ctl00_lblSize" style="font-style:italic;">74.61 kB</span><em>)</em>
<a onclick="return ConfirmDeleteAttachment(this, 'Please confirm deletion', 'Are you sure you wish to delete this attachment?');"
id="ctl00_mainContent_wizNewIPR_dlAttachments_ctl00_btnDelAttach" href="javascript:__doPostBack('ctl00$mainContent$wizNewIPR$dlAttachments$ctl00$btnDelAttach','')">DELETE</a></li>
</span>
</ul>
我正在使用的jQuery函数是一个简单的Yes / No对话框,用于确认删除附件。这是Javascript源代码:
//Confirm Delete Attachment dialog
var delConfirmed = false;
function ConfirmDeleteDialog(obj, title, dialogText) {
if (!delConfirmed) {
//add the dialog div to the page
$('body').append(String.Format("<div id='confirmDeleteDialog' title='{0}'><p>{1}</p></div>", title, dialogText));
//create the dialog
$('#confirmDeleteDialog').dialog({
modal: true,
resizable: false,
draggable: false,
close: function(event, ui) { $('body').find('#confirmDeleteDialog').remove(); },
buttons:
{
'Yes, delete it': function() {
$(this).dialog('close');
delConfirmed = true;
if (obj) obj.click();
},
'No, keep it': function() {
$(this).dialog('close');
}
}
});
}
return delConfirmed;
}
我从http://markmintoff.com/2011/03/asp-net-jquery-confirm-dialog/得到了这个 - 它看起来非常简单而且有道理,但由于某种原因它不适合我。我从来没有得到jQuery-UI确认对话框,它只是在我点击按钮时触发我的按钮的OnClick事件。
答案 0 :(得分:2)
答案是让LinkButton(“ConfirmDeleteAttachment”)的OnClientClick事件中的函数调用与我正在调用的函数的名称相匹配!这只是一个愚蠢的错字。
这个答案归功于开发人员(Mark Mintoff,见http://markmintoff.com的博客)我的代码 - 我给他发了电子邮件,他指出了我的错误。
答案 1 :(得分:0)
删除单引号
[id$=btnDelAttach]