Question

I want to call a JavaScript function to collapse/expand.

I am using this code in asp:repeater ItemTemplate on span

onclick="javascript:funCollExp(this,'<%= P1.ClientID %>');"

How do I pass Control.ClientID?

It replaces P1.ClientID as a string on the page.

Was it helpful?

Solution

You just need to do like this

"onclick="javascript:funCollExp(this,'" + P1.ClinetID + "');"

full code for you make use of itemdatabound event like this

markup

<asp:Repeater id="myRepeater" 
       OnItemDataBound="myRepeater_ItemDataBound" runat="server">
    <ItemTemplate>
        <asp:button id="myDiv" runat="server">......</asp:button>
    </ItemTemplate>
</asp:Repeater>

codebehind

protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if(e.Item.ItemType == ListItemType.Item 
           || e.Item.ItemType == ListItemType.AlternatingItem)
    {
      Button mybtn = e.Item.FindControl("mybtn") as bUTTON;

      mybtn.Attributes.Add("ONCLICK", "MYFUNCTION(this,'" + P1.ClientID + "');");
    }
}

OTHER TIPS

All you need to do is, use it this way

"onclick="javascript:funCollExp(this,'" + P1.ClinetID + "');"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top