Troubles changing the font color for 'disabled' radiolist control

I was recently asked if it's possible to display the items of a disabled radiolist control in a font color other than gray.  At first this might seem somewhat trivial, but after reading some posts it does seem rather practical given that a page may be displayed using different fonts and colors which may prevent the user from clearly seeing the radiolist control (it doesn't look too good when there's a gray' background).

I have tried to setting the radiolist control using an IE tag to make it uneditable,
eg.

rdlstControl.Attribute.Add("contentEditable", "false");

but this does not work.

 

 I have tried adjusting the font color,

rdlstControl.Attribute.Add("style", "color:black");

but this does not work,

 

There is no 'readonly' attribute for the ASP.NET radiolist control.

I have read that some people use images in place of the radiobutton, but this seems a little extreme.  Does anyone have suggestions?

 

Thanks,
Meister1867

 

 

0
Meister1867
9/26/2008 9:15:04 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
653 Views

Similar Articles

[PageSpeed] 3

Meister1867:

I was recently asked if it's possible to display the items of a disabled radiolist control in a font color other than gray.

 I have tried adjusting the font color,

rdlstControl.Attribute.Add("style", "color:black");

but this does not work,


 

I don't think if there's a way to change the fore color of the disabled ListItems or Controls in ASPNET. If there's any then, disabling of controls will not make any sense if you change the fore color rather than Gray color..

If you really want to disable the RBL ListItem without changing the color to default Gray, then you can instead disable the onclick of a particular items in the RBL to retain its normal look/color in the page.. see below

 

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem onclick ="return false;">A</asp:ListItem>
            <asp:ListItem>B</asp:ListItem>
</asp:RadioButtonList>
  

 

Meister1867:

rdlstControl.Attribute.Add("contentEditable", "false");

but this does not work.


 

You can use Enabled property of the RBL ListItems to make the it un-editable... One way is to set at declaratively in the markup like below

 

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem Enabled="false">A</asp:ListItem>
            <asp:ListItem>B</asp:ListItem>
</asp:RadioButtonList>
  
Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
9/26/2008 9:34:50 PM

Hi Vinz,

Thanks for the response.  When I try to use onclick="return false;" it doesn't select the button, but it does unselect the button I want selected.   The result is that not control is selected.  Setting Enabled="false" is pretty much we're trying to avoid.  The button and text become greyed out and unreadable if the background is greyed out.

I put together a little code trying to discover what can be done.  The desired affect can be done using a form input control using type=radio and putting some Javascript to it.  But since we're dealing with a RadioButtonList control, it would be ideal if we could have something like Read-Only = true for the control.  That option doesn't exist for a RadioButtonList though.  Oddly enough... while I was putting some of the code together, I notice that the parser displays a warning message about using "ID"s for a ListItem control.  Strange...  Because I can't link an ID to the control, I can't link the Javascript to the control either.  So my little work-around isn't working :(

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="toggle._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
<
head runat="server">
<title></title>
<script type="text/javascript">

// selectNO()
// this works nicely. Unfortuneately it doesn't work on the
// RadioButtonList control
function selectNO()
{
  if(!document.getElementById || !document.createTextNode)
  {
  return;
  }

  //alert("calling selectNO function");
  document.getElementById("noButton").checked = true;
}

// selectItemTwo()
// this attempts to prevent the user from changing the selected item,
// but it doesn't work.
function selectItemTwo()
{
 
if (!document.getElementById || !document.createTextNode)
  {
 
return;
  }
  document.getElementById(
"itemTwo").checked = true;
}
</script>

 

</head>

<body>

<div style="background: gray; color: Yellow;">

 

<form id="form1" runat="server">

<p>this is the RadioButtonList control</p>

<asp:RadioButtonList ID="rdlst1" runat="server">

<asp:ListItem id="itemOne" onclick="selectItemTwo()">YES</asp:ListItem>

<asp:ListItem id="itemTwo" Selected="True">NO</asp:ListItem>

</asp:RadioButtonList>

</form>

<br />

<br />

<p>***This is an input control using type=radio. This pretty much does what

we're trying to do with a RadioButtonList</p>

<form action="">

<input id="yesButton" type="radio" name="radio1" value="YES" onclick="selectNO()" />YES<br />

<input id="noButton" type="radio" name="radio1" value="NO" checked="checked" />NO<br />

</form>

<br />

<br />

<p>This is an input control with type=radio. This isn't what we would want, but

it is kind of doing what the RadioButtonList is doing when disabled... Graying out

everything.</p>
<div style="color:Gray">
<form action="">
<input id="Radio3" type="radio" name="radio1" value="YES" disabled />YES<br />
<input id="Radio4" type="radio" name="radio1" value="NO" checked disabled />NO<br />
</form>
</div>
</div>
</body>
</
html>

 

Meister 1867

0
Meister1867
9/29/2008 7:09:26 AM
Reply:

Similar Artilces:

How to change tree view's (web control) back color, font color and font size using CSS (Cascading Style Shteets)
Hi All, I have created tree view (web control) but i want to change all the properties of it, through single style sheet. Like all other controls (label, text box and combo box) it's not possible to change all the properties of treeview through single style sheet by including it to the contol ???? Please help........ MAITRAY. Sorry. No external css. but these attributes: DefaultStyle="background:#CCCCCC;border:solid 1px;color:black;font-size:8pt" HoverStyle="color:blue;font-name:Arial" SelectedStyle="c...

How to Dist Between 'Web Forms' and 'HTML' Controls in VS 2005 IDE
I am using ASP.NET 2.  In books and articles, authors refer to and distinguish between 'Web' controls and 'HTML' controls.In the actual Vis Studio IDE toolbox for web forms,  I have one list of controls called 'Standard' containing controls like 'Button' etc. There is also a list labelled 'HTML'  with things like 'INPUT (button)' . There are a few other lists, but none labelled 'Web'. Where are the 'Web' controls found and what are they called in the IDE?  Same for the 'HTML' controls.   I see references in books to 'HTML' controls called 'TextBox', but I d...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

System.Web.HttpException: Control 'ctl00_main_Wizard1' of type 'Wizard' must be placed inside a form tag with runat=server.
I can't figure out why it is saying that. . . the content window that it is in and the wizard itself both have runat="server" set in their tags 2 things to check..1. Do you have the main <form runat="server'></form> tags ( the wizard would be between these tags)2. look for typos - something mistyped will prevent .Net from seeing the form tagHope That HelpsAll that wander, are not lost...What were we talkin bout...

superreview requested: [Bug 79603] Disable color controls when 'Use system color' is checked : [Attachment 313971] Label disabling patch v1.1a
Ian Neal <iann_bugzilla@blueyonder.co.uk> has asked neil@parkwaycc.co.uk <neil@httl.net> for superreview: Bug 79603: Disable color controls when 'Use system color' is checked https://bugzilla.mozilla.org/show_bug.cgi?id=79603 Attachment 313971: Label disabling patch v1.1a https://bugzilla.mozilla.org/attachment.cgi?id=313971&action=edit ------- Additional Comments from Ian Neal <iann_bugzilla@blueyonder.co.uk> Changes since v1.1: * Labels now have the same disabled status as their associated colorpicker. ...

superreview granted: [Bug 79603] Disable color controls when 'Use system color' is checked : [Attachment 313971] Label disabling patch v1.1a
neil@parkwaycc.co.uk <neil@httl.net> has granted Ian Neal <iann_bugzilla@blueyonder.co.uk>'s request for superreview: Bug 79603: Disable color controls when 'Use system color' is checked https://bugzilla.mozilla.org/show_bug.cgi?id=79603 Attachment 313971: Label disabling patch v1.1a https://bugzilla.mozilla.org/attachment.cgi?id=313971&action=edit ...

'System.Web.UI.Control.Context' denotes a 'property' where a 'class' was expected
I get the following error when trying to compile my project. The call to Context lies in a usercontrol. It works fine when called from a page, but how do I call it from a usercontrol? private User _currentUser = new User(Context.User.Identity.Name); 'System.Web.UI.Control.Context' denotes a 'property' where a 'class' was expected Firefox - The browser you can trust Update: private User _currentUser = new User(Context.User.Identity.Name);Is declared inside the class, not in a function. Like: public class Someclass : System.Web.UI.UserControl { private User _currentUser = new...

Control Id 'TextBox1' changes to 'ctl00_ContentPlaceHolder1_TextBox1'
Control Id 'TextBox1' changes to 'ctl00_ContentPlaceHolder1_TextBox1'  when viewed in page source. I can not get the value of my textbox in javascript because it can not find either 'TextBox1'  or 'ctl00_ContentPlaceHolder1_TextBox1'  . Master pages require Place holders so I am stuck with it, any ideas? That is because of INamingContainer. You'll need to use the ClientID property to get a reference to the ID rendered at runtime. i.e. TextBox1.ClientID RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question Thanks mate it wor...

superreview denied: [Bug 79603] Disable color controls when 'Use system color' is checked : [Attachment 312934] Disable and lock checking patch v1.0a
neil@parkwaycc.co.uk <neil@httl.net> has denied Ian Neal <iann_bugzilla@blueyonder.co.uk>'s request for superreview: Bug 79603: Disable color controls when 'Use system color' is checked https://bugzilla.mozilla.org/show_bug.cgi?id=3D79603 Attachment 312934: Disable and lock checking patch v1.0a https://bugzilla.mozilla.org/attachment.cgi?id=3D312934&action=3Dedit ------- Additional Comments from neil@parkwaycc.co.uk <neil@httl.net> Unfortunately disabling colourpickers doesn't work correctly - the binding simply makes a bold claim that it's...

superreview requested: [Bug 79603] Disable color controls when 'Use system color' is checked : [Attachment 312933] Disable and lock checking patch v1.0
Ian Neal <iann_bugzilla@blueyonder.co.uk> has asked neil@parkwaycc.co.uk <neil@httl.net> for superreview: Bug 79603: Disable color controls when 'Use system color' is checked https://bugzilla.mozilla.org/show_bug.cgi?id=79603 Attachment 312933: Disable and lock checking patch v1.0 https://bugzilla.mozilla.org/attachment.cgi?id=312933&action=edit ------- Additional Comments from Ian Neal <iann_bugzilla@blueyonder.co.uk> This patch: * Disables the color pickers when system colors box is checked as long as picker pref is not locked. * Re-enables the col...

superreview canceled: [Bug 79603] Disable color controls when 'Use system color' is checked : [Attachment 312933] Disable and lock checking patch v1.0
Ian Neal <iann_bugzilla@blueyonder.co.uk> has canceled Ian Neal <iann_bugzilla@blueyonder.co.uk>'s request for superreview: Bug 79603: Disable color controls when 'Use system color' is checked https://bugzilla.mozilla.org/show_bug.cgi?id=79603 Attachment 312933: Disable and lock checking patch v1.0 https://bugzilla.mozilla.org/attachment.cgi?id=312933&action=edit ...

superreview requested: [Bug 79603] Disable color controls when 'Use system color' is checked : [Attachment 312934] Disable and lock checking patch v1.0a
Ian Neal <iann_bugzilla@blueyonder.co.uk> has asked neil@parkwaycc.co.uk <neil@httl.net> for superreview: Bug 79603: Disable color controls when 'Use system color' is checked https://bugzilla.mozilla.org/show_bug.cgi?id=79603 Attachment 312934: Disable and lock checking patch v1.0a https://bugzilla.mozilla.org/attachment.cgi?id=312934&action=edit ------- Additional Comments from Ian Neal <iann_bugzilla@blueyonder.co.uk> Correct patch that doesn't try adding a second pref-appearance.js entry to jar.mn ...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

Web resources about - Troubles changing the font color for 'disabled' radiolist control - asp.net.web-forms

Resources last updated: 12/7/2015 9:32:46 PM