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) {

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

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

  • 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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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