Using Javascript in ASP.NET User Control

Posted on 2006-04-12
Last Modified: 2008-01-09
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,

 Page.RegisterStartupScript("spellCheck", "<script language='JavaScript'>document.getElementById('txtBox').value = SpellChecker(document.getElementById('txtBox').value);</script>")
Question by:mcgants
    LVL 17

    Accepted Solution


    Page.RegisterStartupScript("spellCheck", "<script language='JavaScript'>document.getElementById('" & txtBox.ClientId & "').value = SpellChecker(document.getElementById('" & txtBox.ClientId & "').value);</script>")
    LVL 6

    Author Comment

    you're officially a star :D
    that's been plaguing me for hours!!!


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now