RadioButton with Image instead of text

I want to have RadioButton with Image instead of text, that clicking on image the check-box will be selected
 
In the thread it is shown Radio button (without any text) and image on it's side.(but not inside radio-button)
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="A1"
/><asp:image runat="server" id="Image2" /><br />
 
Radiobuttonlist Image Setting thread  suggests to use code
RadioButtonList1.Items.Add(New ListItem("<img src=""" + s + """/>", s))

It will be useful (TODO) to create derided from RadioButton control- RadioButtonWithImage, similar to what I've done previously : ASP.NET custom control HyperLinkWithImage and ASP.NET custom control CheckBoxWithImage
 
There is somehow related post and thread about creating custom control based on RadioButtonList.

posted @ Friday, May 16, 2008 4:21 PM

Print

Comments on this entry:

# re: RadioButton with Image instead of text

Left by Jason Vogel at 6/2/2008 5:55 AM
Gravatar
I ran into a need for this recently, but from within a composite control in a class library. Unfortunately, the above approach fails in my context due to the relative addressing of the image to the "calling" project. I eventually got around it by using code like the following...

System.Web.UI.HtmlControls.HtmlImage visaImage = new System.Web.UI.HtmlControls.HtmlImage();
visaImage.Src = Page.ClientScript.GetWebResourceUrl(this.GetType(), pathToEmbeddedImageVisa);
visaImage.Alt = "Visa";
visaImage.Border = 0

Getting this to work with IE was another story [involving Javascript].

Jason

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 4 and type the answer here:
 

Live Comment Preview:

 
«September»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011