Using Javascript in ASP.NET User Control

Hello,
I have a usercontrol with a textbox in that I need to perform a javascript function on. The function (SpellCheck) is contained within the control and can be called by the parent page and can be run on parent elements, but my problem comes when I try to run the function for textboxes in the usercontrol.
I get an error saying the object (the textbox on the usercontrol) is null or not an object.

Is there any way of referencing the textbox on the usercontrol via the control itself? Please see below for code

Thanks in advance,
mcg

'CODE:
 Page.RegisterStartupScript("spellCheck", "<script language='JavaScript'>document.getElementById('txtBox').value = SpellChecker(document.getElementById('txtBox').value);</script>")
LVL 6
mcgantsAsked:
Who is Participating?
 
Elvio Lujan.Net Senior DeveloperCommented:
use...

Page.RegisterStartupScript("spellCheck", "<script language='JavaScript'>document.getElementById('" & txtBox.ClientId & "').value = SpellChecker(document.getElementById('" & txtBox.ClientId & "').value);</script>")
0
 
mcgantsAuthor Commented:
you're officially a star :D
that's been plaguing me for hours!!!

cheers,
mcg
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.