Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 };

        SP.UI.ModalDialog.showModalDialog(options);
    }
    catch (Err) {
    }
}
share|improve this question
add comment

2 Answers 2

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. –  user8746 Jun 14 '12 at 16:18
add comment

I solved this with inline ClientID in javascript

share|improve this answer
2  
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
add comment

Your Answer

 
discard

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.