I need to pass div client id to JavaScript of a repeater
I have 3 divs inside a repeater i have onmouseover event i want to grab client id of div element Is there any way i can pass exact client of div element
Can u guys help me out Thanks
If you would like to do it in markup, you can use the following to get the ClientId:
<%# Container.FindControl("_RepeaterEL").ClientID %>
Something like this (if I understood you correctly):
Markup:
<asp:Repeater id="myRepeater" OnItemDataBound="myRepeater_ItemDataBound" runat="server">
<ItemTemplate>
<div id="myDiv" runat="server">......</div>
</ItemTemplate>
</asp:Repeater>
Code-behind:
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HtmlGenericControl myDiv = e.Item.FindControl("myDiv") as HtmlGenericControl;
// you can just pass "this" instead of "myDiv.ClientID" and get the ID from the DOM element
myDiv.Attributes.Add("onmouseover", "doStuff('" + myDiv.ClientID + "');");
}
}
<asp:Panel CssClass="modal hide fade" ID="myModal" runat="server">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Add to cart</h3>
</div>
<div class="modal-body">
<nav>
<iframe seamless src="/ToCart/<%# DataBinder.Eval(Container.DataItem, "code")%>"
style="border-style: none;"> </iframe>
</nav>
</div>
</asp:Panel>
<a data-toggle="modal" href="#<%#Container.FindControl("myModal").ClientID%>">
<div class="add-to-cart-one">+</div>
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With