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
-
-
.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 possiblePerfectPhase said:
.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.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.