[英]how to trigger button click event inside listview with jquery in asp.net?
This is my ListView control: 这是我的ListView控件:
<asp:ListView ID="PortfolioListView" runat="server" onitemcommand="PortfolioListView_ItemCommand">
<ItemTemplate>
<li class="item brick1 <%# Eval(" CategoryName ")%> isotope-item">
<a class="item-popup" href="Gallery/195x195/<%# Eval(" MainImage ") %>" title="<%# Eval(" ShortDesc ") %>">
<img src="Gallery/195x195/<%# Eval("MainImage") %>" alt="<%# Eval("Title") %>" />
<div class="hover">
<span class="Popup">
<i class="fa fa-search-plus"></i>
</span>
<span><%# Eval("CategoryName")%></span>
</div>
</a>
<div class="bottom">
<div class="isotope-title"><span><%# Eval("Title")%></span>
</div>
<div class="like">
<a class="update">
<i class="fa fa-thumbs-o-up"></i>
<span><%# Eval("Counter")%></span>
</a>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="flike">
<asp:LinkButton ID="LikeLBTN" runat="server" CssClass="likeBTN" ClientIDMode="AutoID" CommandName="Like" CommandArgument="<%# Bind('GalleryID') %>">
<i class="fa fa-thumbs-o-up"></i>
<span><%# Eval("Counter")%></span>
</asp:LinkButton>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</li>
</ItemTemplate>
</asp:ListView>
I have a LinkButton inside ListView and onitemcommand
event of listview trigger by LinkButton(CommandName="Like" CommandArgument="<%# Bind('GalleryID') %>")
. 我在ListView内有一个LinkButton和由
LinkButton(CommandName="Like" CommandArgument="<%# Bind('GalleryID') %>")
触发的listview的onitemcommand
事件。
My PortfolioListView_ItemCommand in aspx.cs: 我在aspx.cs中的PortfolioListView_ItemCommand:
protected void PortfolioListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
DBClass dbc = new DBClass();
int index = int.Parse(e.CommandArgument.ToString());
string cmd = e.CommandName;
if (cmd == "Like")
{
string selstr = String.Format("Update Gallery set [Counter]=[Counter]+1 where GalleryID = {0}", index.ToString());
int res = dbc.RunCommand(selstr);
selstr = String.Format("SELECT GalleryID, Title, MainImage, Counter, ShortDesc, CategoryName FROM Gallery inner join GalleryCat on Gallery.CatID = GalleryCat.CatID Order By PDate desc");
dbc.LoadInList(PortfolioListView, selstr);
}
}
I want when click on a
tag with class="update"
in ListView, Click event of LinkButton trigger and my code in PortfolioListView_ItemCommand event be run. 我想在ListView中单击具有
class="update"
a
标记时,运行LinkButton触发器的Click事件和PortfolioListView_ItemCommand事件中的代码。 Now How this should be done with jquery or javascript? 现在,应该如何使用jquery或javascript完成此操作? Thank.
谢谢。
I want when click on 'A' tag with class="update" in ListView, Click event of LiunkButton trigger
我想要在ListView中单击class =“ update”的'A'标签时,LiunkButton触发器的Click事件
Try to add click event to tag a with class update
then when the user click you can trigger another click on tag with id #LikeLBTN
: 尝试添加click事件以使用类
update
标记a,然后在用户单击时可以触发ID为#LikeLBTN
另一点击:
$('body').on('click', '.update', function(){
$('#LikeLBTN').click();
})
Or i suggest to use another hidden link like : 或者我建议使用另一个隐藏链接,例如:
<asp:LinkButton runat="server" ID="SomeControl" onclick="someControlClicked"
style="display:none; />
And instead of $('#LikeLBTN').click();
而不是
$('#LikeLBTN').click();
you can call $('#SomeControl').click();
您可以调用
$('#SomeControl').click();
. 。
Hope this helps. 希望这可以帮助。
Usually client ID of an element is different than the id assigned at server. 通常,元素的客户端ID与服务器上分配的ID不同。 So try fetching clientId first and then try to trigger click.
因此,请尝试先获取clientId,然后尝试触发点击。
document.getElementById('<%= LikeLBTN.ClientID %>').click
You can navigate to specific linkButton
using class in div
. 您可以使用
div
类导航到特定的linkButton
。
Following is a sample code using HTML elements: 以下是使用HTML元素的示例代码:
$(document).on("click", ".update", function() { var aTag = $(this); var contentPanel = $(aTag).next().find(".contentPanel"); var flike = $(contentPanel).find(".flike"); var linkBtn = $(flike).find('.linkBtn'); linkBtn.click(); }) $(document).on("click", ".linkBtn", function() { console.warn("Button clicked"); })
div { margin: 5px; padding: 5px; border: 1px solid gray; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <a class="update">Link</a> <div class="updatePanel"> <div class="contentPanel"> <div class="flike"> <button class="linkBtn">Button</button> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.