I have a div in asp.net webform:
<div class="AddToCartHome" id='AddToCartHome_<%#Eval("id") %>' onClientClick="AddToCartHomeJS();" style="height:auto;width:auto;display:inline;">
<img src="images/addtocart-orange-4_224x81.png" width="120px" height="30px" id="AddToCartButtonHome" onclick="AddToCartFromHome" />
</div>
It is part of a listview. I want to take the id of the list item from the id of the div.
I did:
$(".AddToCartHome").click(function AddToCartHomeJS() {
var id = $(this).attr("id");
document.getElementById('<%=hdnItemID.ClientID %>').value = id.split("_").pop();
return true;
});
I use a hidden field for storing the item ID:
<asp:HiddenField ID="hdnItemID" runat="server" />
It is all working perfect. Now I want to execute a method in code behind for adding the item into session cart
.
public void AddToCartFromHome()
{
-----
-----
-----
}
As you can see, I have written the onclick method in the div, onclick="AddToCartFromHome"
but it is not being fired.
How can I do that?