0

I found the following code in one of the old messages in StackOverflow:

$("#<%=GridView1.ClientID%> tr").click(function(){
    alert("Row clicked");
});

The code above is supposed to call an alert when user clicks in a row of a GridView. What I don't understand, is how to define (in my GridView) what is referred in the above code as "ClientID". What is "ClientID"?

3
  • 1
    You don't need to define the ClientID. Each control has a server side ID and a ClientID. You define the server side ID and the ClientID is defined by the markup engine of asp.net. For instance <asp:TextBox ID="text1" runat="server"/> defines a TextBox control with server side ID text1. We use this ID, to access in code behind file the properties f text 1. When this control will be rendered to html, it will have a clientID, which willhave been generated by the asp.net markup engine. Commented Oct 21, 2013 at 19:41
  • Thank you both very much for your explanation. I see the code that I copied now works. But what if I wanted to the Alert to be called only when user clicks on a certain specific column? Also, please allow me to ask a general question. How do I enter a comment for two or more people who answered my question? It appears that I can Add Commnet to one and then the other. What am I missing? Thank you again. Commented Oct 21, 2013 at 19:58
  • The ClientID property is a automatically generated identification for a control. Commented Oct 22, 2013 at 11:55

1 Answer 1

1

This code <%=GridView1.ClientID%> will be run on server and will be final render as the ID of the grid view, so on the page you will final see probably this

$("#GridView1 tr").click(function(){
    alert("Row clicked");
});

The ClientID gives the final ID that the GridView is use on the html page.

Sign up to request clarification or add additional context in comments.

2 Comments

It also depends if they use Master Pages. Then, ASP will add a ContentPlaceHolderID as prefix to the GridView ID
@NikitaSilverstruk Of course, I just give an idea that is going to be render the id of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.