Custom RadioButtonList with Attribute support for ListItem

M

MattB

I found the listitem class was sealed,

and can't get tooltips for radio button in
a radionbuttonlist, apparently this is by design..

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q309338

no one said why, I would just write a bunch of radiobutton controls
but I have I have a Checklist validator

http://www.dotnetjunkies.com/Article/ECCCD6A6-B312-41CB-87A1-10BB5D641D20.dcik

and want to continue using it, as I am not sure how to get a group of
radiobuttons of Checkboxes in to verify one of them is select

so I wrote the following, all is good except I lose the viewstate of
the
selected radiobutton on postback, I am new to custom controls and they
seem
very dependant on what which class you are overriding....

can anyone help, thanks...m@

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MY.UI
{
/// <summary>
/// Summary description for TooltipRadioButtonList.
/// </summary>
public class TooltipRadioButtonList :
System.Web.UI.WebControls.RadioButtonList
{
protected override void Render(HtmlTextWriter writer)
{
//RenderChildren(writer);
int i = 0;
foreach (ListItem listItem in Items)
{
writer.WriteBeginTag("input");
writer.WriteAttribute("ID",this.UniqueID+"_"+i );
writer.WriteAttribute("type", "radio");
writer.WriteAttribute("name", this.UniqueID);
writer.WriteAttribute("value", listItem.Value, true);
listItem.Attributes.Render(writer);
writer.Write('>');
writer.WriteEndTag("input");
writer.WriteBeginTag("label");
writer.WriteAttribute("for",this.UniqueID+"_"+i );
listItem.Attributes.Render(writer);
writer.Write('>');
HttpUtility.HtmlEncode(listItem.Text, writer);
writer.WriteEndTag("label");
if (i < Items.Count-1)
writer.RenderBeginTag(HtmlTextWriterTag.Br);
writer.WriteLine();
i++;
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top