Dennis Bottjer | ASP.NET + SharePoint Architect, Trainer & Speaker

"An Ounce of Prevention is Worth a Pound of Cure" - Ben Franklin
posts - 168, comments - 59, trackbacks - 41

My Links

News

Add to Technorati Favorites The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Tag Cloud

Archives

Post Categories

Updating ASP.NET Labels with JavaScript

When building custom server controls sometimes it is nice to eliminate the need for a post back.  I say nice but not necessarily easy.  Perhaps you would like to enter dollar amounts into textboxes within grid rows and display the total on the last row all without a post back.  This really isn't that hard using a little Java Script.   For example, you can use the OnChange event for the ASP.NET Textbox control to call a JavaScript function to update the total.  However, what I found a little challenging was figuring out how to access an ASP.NET Label control via Java Script.  This control renders as a html tag.  After some Google searching I found a method that works quite well.

Let's say you have a label control where the id=Errors.  It will essentially render as .  You can access and change the text of this label via Java Script as follows:

document.getElementById('Errors').innerHTML = 'Must be a numeric value';

The above line of code will work in IE5, IE6, NS6

Print | posted on Thursday, November 3, 2005 12:25 AM | Filed Under [ ASP.NET ]

Comments have been closed on this topic.

Powered by: