Link to home
Start Free TrialLog in
Avatar of jvancojr
jvancojr

asked on

Accessing/Setting Text inside a Label Control on an ASP.net Page (C#)

Good Afternoon,
I have been racking my brain on how to access/set the text inside a ASP.NET Label Control with client side javascript.
...And yes i have search this site for answers (for about 2 hours)
I have tried mutliple answers posted here and the closest I can get is 'undefined' to appear in the popup alert i have been using to test the response .
I am looking to grab the results of HTML radiobutton generated dynamically (works like a dream) and store the value a Label Control.
I am also trying to access the text in the lblNumberOfUsers control to let the function check more than one set of radio buttons.

Help...pulling what hair i have left out...lol

function getCheckedValue(objName) {
        
        //var numberOfGuest = document.getElementById('lblNumberOfUsers').text;
        var numberOfGuest = document.getElementsByName('lblNumberOfUsers').innerHTML;
        //var numberOfGuest = document.getElementById('lblNumberOfUsers').innerHTML;
        alert(numberOfGuest);
 
        var radioObj = document.getElementsByName(objName);
        if (!radioObj)
            return "";
        var radioLength = radioObj.length;
        if (radioLength == undefined)
            if (radioObj.checked)
            return radioObj.value;
        else
            return "";
        for (var i = 0; i < radioLength; i++) {
            if (radioObj[i].checked) {
                //return radioObj[i].value;
                alert(radioObj[i].value);
            }
        }
        return "";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mohan_sekar
mohan_sekar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jvancojr
jvancojr

ASKER

I get a build error on '<%= lblNumberOfUsers.ClientID%>'
Error      1      'System.Web.UI.WebControls.Label' does not contain a definition for 'ClientId' and no extension method 'ClientId' accepting a first argument of type 'System.Web.UI.WebControls.Label' could be found (are you missing a using directive or an assembly reference?)      C:\Projects\ECommerce CStar\Main\Source\EcomCStarApps\ECommerceWebSitev2\packages.aspx      26      
you have to capitalize the last 'd'.  The property is ClientID.  The error indicates you spelled the property as ClientId.
I went another direction on this page to get around this issue.
Thanks all for your time