textbox not recognized in client side

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
 
D

Dave Bush

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
 
M

Mark Rae [MVP]

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...
}
 
C

Claudia Fong

view source code shows me this name:

ctl00_ContentPlaceHolder1_ txtBC



Cheers!

Claudi
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top