我有一个可点击的div的问题,我知道如何制作一个可点击的div,但是,我想要点击的div是在转发器中。我用命令名尝试了linkbutton而不是div,但它不太适合我。
我正在尝试做的事情是让div可点击,因为我需要从后面的代码控制它,也许有一个jQuery或c#的解决方案,对我来说都没问题。
我谈到的div是divproblem。
<asp:Repeater runat="server" ID="rpAlbumler" OnItemCommand="rpAlbumler_ItemCommand">
<ItemTemplate>
<div class='<%#Eval("Kategoricss") %>' runat="server" id="dvKategoriler">
<div class="fw-portPreview">
<div class="img_block wrapped_img fs_port_item">
<a class="featured_ico_link" href="portfolio_post_fullscreen_ribbon.aspx">
<asp:Image runat="server" ID="imgkapak" ImageUrl='<%#Eval("Kapakpath") %>' />
</a>
<div class="bottom_box">
<div class="bc_content">
<h5 class="bc_title">
<asp:HyperLink runat="server" ID="hplnkAlbumIcerik" Text='<%#Eval("Abaslik") %>'></asp:HyperLink>
</h5>
<div class="featured_items_meta">
<span>
<asp:Label runat="server" ID="lblKategoriler" Text='<%#Eval("Kategorihazir") %>'></asp:Label></span>
</div>
</div>
<div id="divproblem" class="bc_likes gallery_likes_add">
<i class="stand_icon icon-heart"></i>
<span>
<asp:Label runat="server" ID="lblAlbumBegeni" Text='<%#Eval("Albumbegenisayisi") %>'></asp:Label></span>
</div>
</div>
<div class="portFadder"></div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
答案 0 :(得分:1)
您的<div>
无法使用ID连接到jQuery中的click事件非常简单,因为ID在转发器中多次出现,因此您需要使用{{1}将div绑定到click事件} attribute:
class
其次,要与jQuery click事件背后的代码交谈,您可以使用$(".bc_likes").click(function () { });
并调用C#$.ajax
,您可以在其中编写逻辑代码。
。后面的代码:
[WebMethod]
<强> .ASPX:强>
public partial class RepeaterExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
var p1 = new Product { ID = 1, ProductName = "Banana" };
var p2 = new Product { ID = 2, ProductName = "Apple" };
var p3 = new Product { ID = 3, ProductName = "Orange" };
Repeater1.DataSource = new List<Product> { p1, p2, p3 };
Repeater1.DataBind();
}
}
[System.Web.Services.WebMethod]
public static string ServerCall(int id)
{
return "Server response.Processed ID - " + id;
}
}
public class Product
{
public int ID { get; set; }
public string ProductName { get; set; }
}