[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Javascript get asp label value

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");
0
ChiBella
Asked:
ChiBella
  • 3
1 Solution
 
LordOfPortsCommented:
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 http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx e.g. it would be something like:

var q1_exit = document.getElementById("<%= lblExitDateVQ1.ClientID %>");
0
 
ChiBellaAuthor Commented:


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?
0
 
ChiBellaAuthor Commented:
viewing the source:

ctl00_ContentPlaceHolder1_lblExitDateVQ1
0
 
ChiBellaAuthor Commented:
this finally worked:

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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