[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1324
  • Last Modified:

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>")
0
mcgants
Asked:
mcgants
1 Solution
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now