This is horrible in ASP.NET, because ASP.NET is horrible. The best way is to do this
var myGrid = <%theGrid.ClientId %>
And then use myGrid from there. Do the same with all your client ids, have one ugly block that defines these things, and then use the client side variables.