Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-07-21
5
Medium Priority
?
283 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 1240 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

Industry Leaders: 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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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

730 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