最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin3PV0评论

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 + "');"
Post a comment

comment list (0)

  1. No comments so far