Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass client id of Item in repeater to javascript

Tags:

asp.net

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

like image 355
jhon Avatar asked Jan 25 '11 17:01

jhon


3 Answers

If you would like to do it in markup, you can use the following to get the ClientId:

<%# Container.FindControl("_RepeaterEL").ClientID %>
like image 85
Calciol Avatar answered Nov 15 '22 06:11

Calciol


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 + "');");
    }
}
like image 37
volpav Avatar answered Nov 15 '22 08:11

volpav


<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>
like image 29
d.snissarenko Avatar answered Nov 15 '22 07:11

d.snissarenko