Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Suggested Courses

824 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