最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass Control.ClientID in function in repeater ItemDataBound in aspx page? - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 3

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 + "');");
    }
}

All you need to do is, use it this way

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

评论列表(0)

  1. 暂无评论