Solved

How to set the text of an Asp.net labe control using Java Script.

Posted on 2014-07-21
5
267 Views
Last Modified: 2014-08-18
I have an Asp.net label control. I need to set the text of the control using Java Script. I know that I have to use document.getElementById, however I can't figure out how to do it. Can someone help me out? The value stored in the label control is a floating point number like 345.33

// Asp.net Label control in my Aspx Page.
<asp:Label ID="myLabel" runat="server" visible="true"></asp:Label>


// Now trying to set the text of the label control. My java script function that contains the line of code below,
// is at the top of my Aspx page.

document.getElementById("myLabel").innerHTML = 688
0
Comment
Question by:brgdotnet
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 40211987
Hello brgdotnet,
if you want to use the method document.getElementById() then you need the current label ID as it appears at client side in the browser.
And you can see the Complete id only if you look into the page source as it appears in Browser. You see?
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 310 total points
ID: 40212897
JS seems to be the issue here, please assign the number as string:
document.getElementById("myLabel").innerHTML = '688' 

Open in new window


if the above does not work (e.g. your page has a master page), then you need to get the unique rendered id as follows:
document.getElementById('<%=myLabel.ClientID %>').innerHTML = '688' 

Open in new window

0
 
LVL 2

Author Comment

by:brgdotnet
ID: 40213430
Thanks. I will need to get back with you tomorrow evening to let you know how it goes.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

867 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