textbox not recognized in client side

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

I have a textbox name txtBC but I was trying to check if this textbox is
empty or not.. Jscript gave me this error:

txtBC.value is null or not an object

what should I do?

Cheers!

Claudi
 
Once you've rendered it to your browser, do a view > source and make sure
the ID is still txtBC.

If you are using master pages, the control is most certainly called ctl00_txtBC
and if you have the control in a user control it will be prefixed with the
name of the user control followed by an underscore. If you are emitting
the script from your CS or VB code, you can use the ClientId property of
the control to find out what the browser will ultimately see it as.



Dave Bush
http://blog.dmbcllc.com
 
I have a textbox name txtBC but I was trying to check if this textbox is
empty or not.. Jscript gave me this error:

txtBC.value is null or not an object

what should I do?

if (document.getElementById('<%=txtBC.ClientID%>').value.length == 0)
{
// do something...
}
 
view source code shows me this name:

ctl00_ContentPlaceHolder1_ txtBC



Cheers!

Claudi
 
view source code shows me this name:

ctl00_ContentPlaceHolder1_ txtBC

....because txtBC is a "server-side id" for ASP.NET and in the
Javascript (client-side) code you should use <%=txtBC.ClientID%> to
reference to that element. Look at the code that Mark sent above
 
Back
Top