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
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
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 the repeater renders to the browser, you can get the repeater element with:
var rep = $get("<%= rpt.ClientID %>");
Otherwise, wrap a
<DIV id="RepeaterEL"></div>
around the repeater, and access its children either through pure JavaScript (and the childNodes collection), or using JQuery like
$("#RepeaterEL").children("DIV").each(function(i) {
var id = $(this).attr("id"); //<- pointer to DIV });