我有以下asp转发器:
<asp:Repeater runat="server" ID="rptResults">
<ItemTemplate>
<div class="FileFile Large pdf SearchResult" id="<%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>">
<a href='<%# DirectCast(Container.DataItem, FileFolder).Link %>' style="text-decoration:none">
<%# DirectCast(Container.DataItem, FileFolder).BackgroundHTML%>
<p style="float:left;line-height:32px;margin:0px"><%# DirectCast(Container.DataItem, FileFolder).Filename%></p>
</a>
<asp:Button runat="server" OnClientClick="return confirmation(this);" ID="btnDeleteFile" CommandArgument="<%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>" UseSubmitBehavior="false" Text="Delete" Style="float:right;margin-top:8px;cursor:pointer;"/>
<a style="float:right;line-height:32px;margin-right:10px">ID = <%# DirectCast(Container.DataItem, FileFolder).DocStoreID%></a>
</div>
</ItemTemplate>
</asp:Repeater>
<script>
function confirmation(sender) {
if (confirm("Delete file "+ sender.id + "?"))
return true;
else return false;
}
</script>
我希望OnClientClick说:
删除文件######
要执行此操作,我需要传入父div的id或其旁边的<a>
的内容。
目前,我有OnClientClick="return confirmation(this);"
,它在按钮中传递。所以我可以将这些信息存储在按钮的字段中,但我尝试过:
name="%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>"
但这不起作用。是否有任何其他变量可以用来存储它,或者是否可以将引用传递给转发器中的另一个元素?
答案 0 :(得分:1)
您可以在按钮中使用title
属性:
title="<%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>"
然后你的javascript将是
function confirmation(sender){
if(confirm("Delete file " + sender.title + " ?"))
return true;
else
return false;
}
请注意,title
属性旨在显示工具提示,因此用户会在按钮上看到工具包。希望它有所帮助。
答案 1 :(得分:0)
试试这个
OnClientClick="return confirmation('<%= DirectCast(Container.DataItem, FileFolder).DocStoreID %>');"
而你JS
将是
function confirmation(sender) {
if (confirm("Delete file "+ sender + "?"))
return true;
else return false;
}