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:
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 |
![]() |
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, butit 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 |
![]() |