SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating an SPGridView dynamically and adding to my page. It is encased in a web part. How do I access the ClientID of the grid from the javascript on the page?

 function openCommentsDialog( id) {

    try {
        **fails-->**var grid = document.getElementById("_grid");
        //variable to contain the cell of the grid 
        var cell;

        var options = SP.UI.$create_DialogOptions();
        options.url = "SRPChange.aspx" + "?Type=" + type + "&ItemID=" + id;
        options.height = 600;
        options.width = 800;
        options.allowMaximize = false;
        options.Title = "SRP Change Dialog";
        options.args = { Type: type, ItemID: id };

    catch (Err) {
share|improve this question

Like so: var grid = document.getElementById("<%= _grid.ClientID %>");

in jQuery: $("#<%= _grid.ClientID %>");

share|improve this answer
Thank you. Problem is my grid is dynamic and not known at runtime. – Walter Johnson Jun 14 '12 at 16:18

I solved this with inline ClientID in javascript

share|improve this answer
Thanks for coming back to update with the answer. Could you provide more details so that future visitors will be able to use your answer? – Kit Menke Jun 14 '12 at 18:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.