Solved

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

Posted on 2014-07-21
5
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 36

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

628 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