Javascript Referencing Invisible Text Box?

Posted on 2007-10-19
Last Modified: 2008-01-09
I have some javascript that attempst to reference an invisible field on the page which generates an error.
What is the best approach to fixing this?

var iNotVisible = parseInt(document.getElementById('ctl00_ContentPlaceHolder1_tbNotVisible').value);

<asp:TextBox ID="tbNotVisible" runat="server" Visible="False" Height="7px" Width="66px"></asp:TextBox><br />

Question by:ChiBella
    1 Comment
    LVL 3

    Accepted Solution

    It looks like you are using ASP.NET.  If this is correct, then you will not be able to reference the textbox via javascript if you set visible to false.  Here is why:

    When you set Visible="False" in the page, this is processed on the server side, and the control will never be rendered as html.

    What you can do however, is set Visible="true" and then use CSS to hide the element.  That way, the server control will be rendered as html and you will be able to access it via javascript.  So something like:

    <asp:TextBox ID="tbNotVisible" runat="server" Visible="true" Height="7px" Width="66px" style="display:none"></asp:TextBox><br />

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now