$('#<%=nameLabel.ClientID%>') is being used in my script for jquery.
When this is in … block in tha page , it works fine ,as its a content page it is evaluated to $('#ctl00_contentPanel1_nameLabel') properly, i can see it while debugging scripts.
however , when i keep the same script in .js file it does not evaulate to $('#ctl00_contentPanel1_nameLabel') hence does not work.
It is sure that .js script is loaded as i can debug & some other functions also work.
I am using ScriptManagerProxy.
Please help ?
Thanks in advance.
There are two reasons that this doesn’t work in a .js file.
Javascript files are not run through the ASP.NET engine, so the server tag <%=…%> is never executed. (If you have full control over the IIS you can register the files to be run by the engine, but it still won’t work because of the second reason.)
The .js file is requested separately from the page, so the server control that you want to get the id for doesn’t exist any more. It only exists while the request for the main page is handled.
You can put code to assign the id to a variable in the page, and use that variable in the .js file: