Javascript get asp label value

Posted on 2009-02-13
Last Modified: 2012-06-27
Can someone instruct me on how to capture a label or hidden value within javascript prior to an asyn partial postback?
I need to get the value of a field in order to disable an option in a modal popup on the client.

tried to pull value from a label but the label is not accessible in javascript. How can I capture the label value in javascript?

var q1_exit = document.getElementById("lblExitDateVQ1");
Question by:ChiBella
    LVL 19

    Accepted Solution

    The getElementById Javascript function should work however the client-side ID of the label can change by the time it is rendered. Try displaying the web page in the browser then view the source code of the generated web page to learn the actual client-side ID of the label.

    There is also a ClientID property for the label that you could insert dynamically, see e.g. it would be something like:

    var q1_exit = document.getElementById("<%= lblExitDateVQ1.ClientID %>");

    Author Comment


    var q1_exit = document.getElementById("<%= lblExitDateVQ1.ClientID %>");
     is no longer undefined, but always returns "null".

    Can it be a timing issue since these values are not set until a partial postback occurs on the page?

    Author Comment

    viewing the source:


    Author Comment

    this finally worked:

    var q1_exit = document.getElementById('ctl00_ContentPlaceHolder1_lblExitDateVQ1').innerHTML;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    759 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

    13 Experts available now in Live!

    Get 1:1 Help Now