Accessing a control in asp.net content page through Javascript

Posted by rocksolid on Stack Overflow See other posts from Stack Overflow or by rocksolid
Published on 2010-06-07T13:34:01Z Indexed on 2010/06/07 13:42 UTC
Read the original article Hit count: 265

Hi,

I have a form in my content page for which I am doing some client side validations via Javascript. The Javascript behaves as expected if I place the JS code directly in the content page. But if I place the JS code in it's own file and try accessing that from the content/master page (through the script tag's src attribute), I get a run time error when the validation function in JS being called.

To be specific, I get the below error. Microsoft JScript runtime error: Objected expected/required at this line - document.getElementById('<%=txtemailId.ClientID %>').value

txtemailId is in the content page.

Javascript code is placed in validation.js and accessed via master page.

The reason I guess is that when .net is parsing the files, it is unable to substitute txtemailId.ClientID with the client side value that would be generated later on. So, how should one go about it? Thanks!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about JavaScript