I am trying to group radiobuttons together with groupname property..
It doesnt work because of the naming convention in asp.net while rendering..
so i tried to inherited the radiobutton control and overrided radiobutton and created my own control..
it solved the grouping problem but its not taking care of viewstate for some reason…
so all my radiobuttons are are viewstate-less..
here’s my code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace CustomControl
{
public class GroupRadioButton : RadioButton
{
public GroupRadioButton()
: base()
{ }
protected override void Render(HtmlTextWriter writer)
{
base.Render(new GroupedRadioButtonTextWriter(writer,this.GroupName));
}
}
public class GroupedRadioButtonTextWriter : HtmlTextWriter
{
private string groupName;
public GroupedRadioButtonTextWriter(HtmlTextWriter baseWriter, string groupName) : base(baseWriter)
{
this.groupName = groupName;
}
public override void AddAttribute(HtmlTextWriterAttribute key, string value)
{
if (key == HtmlTextWriterAttribute.Name)
{
base.AddAttribute(key, this.groupName);
}
else
{
base.AddAttribute(key, value);
}
}
}
}
can anyone help ?
I think you misused your time by implementing your own radio button considering the fact that RadioButtonList is the component you should be using.