Solved

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

Posted on 2014-07-21
5
258 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. I will need to get back with you tomorrow evening to let you know how it goes.
0

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

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now