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.
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.
Share Improve this question edited Jul 21, 2012 at 8:15 Pranay Rana 177k37 gold badges243 silver badges266 bronze badges asked Jul 21, 2012 at 7:46 Chirag KhatsuriyaChirag Khatsuriya 6351 gold badge14 silver badges27 bronze badges 1- check my edit in answer that will help you to get your task done – Pranay Rana Commented Jul 21, 2012 at 7:54
2 Answers
Reset to default 3You 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 + "');");
}
}
All you need to do is, use it this way
"onclick="javascript:funCollExp(this,'" + P1.ClinetID + "');"