Hello,
what reasons may be, when the $find don't find?
I'm searching a webdatagrid with the id="grid" with the following code:
var grid = $find("grid");
But I always get null
I'm using version 12.1 and IE9.
Bodo
Hi, Bodojaeger.
Have you tried using the client id:
var grid = $find("<%=this.grid.ClientID%>");
Best regards,
Nikolay
Hi again, Bodojaeger.
I want to be more accurate in my answer, that's why I will provide you one more beautiful way to resolve your issue.
As I've already told you the first way is to pass the id in server tags, using the ClientID property of the grid. In this way you will be sure that $find() will search existing id on the generated HTML:
In this way when you say id="grid" this means that ServerID of the control is going to be "grid", but the 'ClientID' is constructed and contains as a prefix all his parent id, that's why 'ClientID' is equal to something similar to the "parent1ID_parent2ID_...._grid".
But if you want 'ClientID' of the gird to be the same as the 'ServerID', then in the definition of the WebDataGrid you need the following code:
<ig:WebDataGrid ID="grid" runat="server" ClientIDMode="Static">
</ig:WebDataGrid>
By defining 'ClientIDMode' as static you are saying that your 'ClinetID' and 'ServerID' will have the same values. Therefore your initial code:
will find the grid and will not return null.
Just you need to know that you can use 'ClientIDMode' property only if you have .NET Framework higher or equal to version 4.
I hope this will clear your doubts and I'm here if you have more questions.
Hi Nikolay,
thanks for your detailed answer.
I've tried both versions.
1. I'm using VB.NET 4.0, so I changed the code to
var
grid = $find("<%=Me.grid.ClientID%>");
and it works.
2. The way with the ClientIDMode works too.
What is the prefered version? Are there some constraints by using one of this versions? I think you won't rename the ID's without any reason.
I'm happy to hear that it works the both ways for you. I've now marked the answer as "Suggested". If somebody else have the same issue he will be able to resolve it.
You can use both ways, just need to know that you should have .NET Framework 4 and above when ClientIDMode is used. If I know that my solution is going to use that version of the framework, I will use the second approach for sure, just because it will not be necessary to write server tags inside the JavaScript code. But this is just my opinion.