Posted By: jmhemadri | Sep 30th, 2008 @ 4:53 AM
page 1 of 1
Comments: 2 | Views: 567
Hi

Generally we are calling ASP.NET controls in javascript like

<SCRIPT LANGUAGE="JAVASCRIPT">
function getValue()
{
    var id1=document.getElementById("<%= txtUsername.ClientID %>");
}
</SCRIPT>
<form>
<asp:textbox id="txtUsername" runat="server"></asp:textbox>
</form>
In the above case if we write both asp.net and javascript in the same page the above code works fine. if we write javascirpt code in another page, the clientid is not working, is there any another method to call?

Thanks
Hemadri
PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman

.js files are not parsed in the same way as aspx so the "<%= txtUsername.ClientID %>" expresion is not evaluated.  if you want to move your javscript to an seperate file, you have to leave the portions that extract the clientID on the ASPX page that declares the control and then use that to set the values into some storage that your .js file can use. 
Yes , I have also tried this and we cannot use the clientId in a .js file...  Need to pass them as parameters if possible
page 1 of 1
Comments: 2 | Views: 567
Microsoft Communities