<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Custom Server Controls</title><link>http://forums.asp.net/19.aspx</link><description>All about building ASP.NET server controls. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=12&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Customizing RadioButtonList</title><link>http://forums.asp.net/thread/1614649.aspx</link><pubDate>Sat, 10 Mar 2007 17:06:17 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1614649</guid><dc:creator>aivanoff</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1614649.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=1614649</wfw:commentRss><description>&lt;p&gt;I found a simpler solution. A simple javascript sets the width of &amp;lt;input type="radio"&amp;gt; to 0px making it disappear. So now RadionButtonList looks like a list of labels but behaves like RadionButtonList. Next step is customizing labels using javascript with styles. 
&lt;p&gt;Looks like I am going to create extender control next.&lt;/p&gt;&lt;/p&gt;</description></item><item><title>Re: Customizing RadioButtonList</title><link>http://forums.asp.net/thread/1614598.aspx</link><pubDate>Sat, 10 Mar 2007 15:54:54 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1614598</guid><dc:creator>joteke</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1614598.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=1614598</wfw:commentRss><description>&lt;p&gt;Edit: Updated to support both AutoPostBack&amp;nbsp;and non-AutoPostBack scenarios&lt;/p&gt;
&lt;p&gt;Replace with what? Are you going to show some sort of image instead of RB? There could be multiple ways of doing it and the impact is&amp;nbsp;then on&amp;nbsp;implementation of RenderItem and possibly overriding LoadPostdata and perhaps registering some script to accomplish it. For example writing the text and value of ListItem into custom attribute on DIV element and then setting into hidden field with javascript (hidden field named based on the index of the ListItem that was clicked and value then it's value). The plumbing could also be helped in how you put it to pass the valöues tpo the server. For example one hack:&lt;/p&gt;&lt;pre class=coloredcode&gt;&amp;nbsp;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;public class&lt;/span&gt; MyRadioButtonList : RadioButtonList
    {

        &lt;span class=kwd&gt;private string&lt;/span&gt; HiddenValueFieldName
        {
            &lt;span class=kwd&gt;get&lt;/span&gt;
            {
                &lt;span class=kwd&gt;return this&lt;/span&gt;.ClientID + &lt;span class=st&gt;"_theValue"&lt;/span&gt;;
            }
        }

        &lt;span class=kwd&gt;private string&lt;/span&gt; DivArrayName
        {
            &lt;span class=kwd&gt;get&lt;/span&gt;
            {
                &lt;span class=kwd&gt;return this&lt;/span&gt;.ClientID + &lt;span class=st&gt;"_theDivs"&lt;/span&gt;;
            }
        }

        &lt;span class=kwd&gt;protected override void&lt;/span&gt; OnPreRender(EventArgs e)
        {
            &lt;span class=kwd&gt;base&lt;/span&gt;.OnPreRender(e);
            
            &lt;span class=kwd&gt;string&lt;/span&gt; script = &lt;span class=st&gt;""&lt;/span&gt;;
            script += &lt;span class=st&gt;"function setValue(theDiv){"&lt;/span&gt;;
            script += &lt;span class=st&gt;"document.getElementById('"&lt;/span&gt; + HiddenValueFieldName + &lt;span class=st&gt;"').value = theDiv.getAttribute('value');"&lt;/span&gt;;

            &lt;span class=kwd&gt;if&lt;/span&gt;(&lt;span class=kwd&gt;this&lt;/span&gt;.AutoPostBack) 
                script += Page.ClientScript.GetPostBackEventReference(&lt;span class=kwd&gt;this&lt;/span&gt;, &lt;span class=st&gt;""&lt;/span&gt;, &lt;span class=kwd&gt;false&lt;/span&gt;);
            &lt;span class=kwd&gt;else&lt;/span&gt;{
                script += &lt;span class=st&gt;"theDiv.style.backgroundColor='gray';"&lt;/span&gt;;
                script += &lt;span class=st&gt;"for(i=0;i&amp;lt;"&lt;/span&gt; + DivArrayName + &lt;span class=st&gt;".length;i++){"&lt;/span&gt;;
                script += &lt;span class=st&gt;"var theVal="&lt;/span&gt; + DivArrayName + &lt;span class=st&gt;"[i];"&lt;/span&gt;;
                script += &lt;span class=st&gt;"if(theDiv.getAttribute('id') != theVal)"&lt;/span&gt;;
                script += &lt;span class=st&gt;"document.getElementById(theVal).style.backgroundColor='white';"&lt;/span&gt;;
                script += &lt;span class=st&gt;"}"&lt;/span&gt;;
            }

            script += &lt;span class=st&gt;"}"&lt;/span&gt;;
            Page.ClientScript.RegisterStartupScript(&lt;span class=kwd&gt;this&lt;/span&gt;.GetType(),&lt;span class=st&gt;"setValue"&lt;/span&gt;,script,&lt;span class=kwd&gt;true&lt;/span&gt;);

            &lt;span class=cmt&gt;//register the hidden field&lt;/span&gt;
            Page.ClientScript.RegisterHiddenField(HiddenValueFieldName, &lt;span class=st&gt;""&lt;/span&gt;);

            &lt;span class=cmt&gt;//register that LoadPostdata will be called even if control's UniqueID is not on post data collection&lt;/span&gt;
            Page.RegisterRequiresPostBack(&lt;span class=kwd&gt;this&lt;/span&gt;); 

            &lt;span class=cmt&gt;//this is playing for the client-side color selection :-)&lt;/span&gt;
            System.Text.StringBuilder sb = &lt;span class=kwd&gt;new&lt;/span&gt; System.Text.StringBuilder();
            &lt;span class=kwd&gt;foreach&lt;/span&gt;(ListItem litem &lt;span class=kwd&gt;in this&lt;/span&gt;.Items)
            {
                sb.Append(&lt;span class=st&gt;"'"&lt;/span&gt;); 
                sb.Append(&lt;span class=kwd&gt;this&lt;/span&gt;.ClientID);
                sb.Append(&lt;span class=kwd&gt;this&lt;/span&gt;.IdSeparator);
                sb.Append(litem.Value);
                sb.Append(&lt;span class=st&gt;"'"&lt;/span&gt;); 
                sb.Append(&lt;span class=st&gt;","&lt;/span&gt;); 
            }

            &lt;span class=kwd&gt;string&lt;/span&gt; s = sb.ToString().TrimEnd(&lt;span class=st&gt;','&lt;/span&gt;);
            Page.ClientScript.RegisterArrayDeclaration(&lt;span class=kwd&gt;this&lt;/span&gt;.ClientID + &lt;span class=st&gt;"_theDivs"&lt;/span&gt;, s); 
            
        }

        &lt;span class=kwd&gt;protected override bool&lt;/span&gt; LoadPostData(&lt;span class=kwd&gt;string&lt;/span&gt; postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            &lt;span class=cmt&gt;//wrap the existing loading logic to get the LiostItem value from our hidden field&lt;/span&gt;
            &lt;span class=kwd&gt;return base&lt;/span&gt;.LoadPostData(HiddenValueFieldName, postCollection);
        }

        &lt;span class=kwd&gt;protected override void&lt;/span&gt; RenderItem(ListItemType itemType, &lt;span class=kwd&gt;int&lt;/span&gt; repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
        {
            &lt;span class=cmt&gt;//render the thing out as a DIV&lt;/span&gt;
            ListItem item=&lt;span class=kwd&gt;this&lt;/span&gt;.Items[repeatIndex];
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, &lt;span class=st&gt;"1px"&lt;/span&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, &lt;span class=st&gt;"black"&lt;/span&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, &lt;span class=st&gt;"solid"&lt;/span&gt;);

            writer.AddAttribute(HtmlTextWriterAttribute.Value, item.Value);
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, &lt;span class=st&gt;"setValue(this)"&lt;/span&gt;);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, &lt;span class=kwd&gt;this&lt;/span&gt;.UniqueID + &lt;span class=kwd&gt;this&lt;/span&gt;.IdSeparator + item.Value);  
     
            &lt;span class=kwd&gt;if&lt;/span&gt; (item.Selected)
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, &lt;span class=st&gt;"gray"&lt;/span&gt;);

            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.Write(item.Text); 
            writer.RenderEndTag(); 
           
        }
    }&lt;/pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: I just played this out based on my imagination so it *really* might not be what you need but demonstrates the idea. :-) &lt;/p&gt;</description></item><item><title>Re: Customizing RadioButtonList</title><link>http://forums.asp.net/thread/1614532.aspx</link><pubDate>Sat, 10 Mar 2007 14:31:54 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1614532</guid><dc:creator>aivanoff</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1614532.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=1614532</wfw:commentRss><description>&lt;p&gt;Can you provide some pointers how to properly deal with IPostBackDataHandler, LoadPostData etc.? This is where I failed. And this is exactly what I need: replace radio button with something else.&lt;/p&gt;</description></item><item><title>Re: Customizing RadioButtonList</title><link>http://forums.asp.net/thread/1614352.aspx</link><pubDate>Sat, 10 Mar 2007 09:08:14 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1614352</guid><dc:creator>joteke</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1614352.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=1614352</wfw:commentRss><description>&lt;p&gt;How did you implement it? Did you call base.RenderItem in your impl somewhere. For example this works quite fine (in ASP.NET 2.0)&lt;/p&gt;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;public class&lt;/span&gt; MyRadioButtonList : RadioButtonList
    {
        &lt;span class=kwd&gt;protected override void&lt;/span&gt; RenderItem(ListItemType itemType, &lt;span class=kwd&gt;int&lt;/span&gt; repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
        {
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, &lt;span class=st&gt;"1px"&lt;/span&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, &lt;span class=st&gt;"black"&lt;/span&gt;);
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, &lt;span class=st&gt;"solid"&lt;/span&gt;);
            writer.RenderBeginTag(HtmlTextWriterTag.Div); 
            &lt;span class=kwd&gt;base&lt;/span&gt;.RenderItem(itemType, repeatIndex, repeatInfo, writer);
            writer.RenderEndTag(); 
        }
    }&lt;/pre&gt;&amp;nbsp; Butr certainly it works as it calls the base implementation which uses RadioButton controls internally. basically you could be able to do it without rdb, but you need to deal with the IPostBackDataHandler implementation of the RadioButtonList which expects event argument toi LoadPostdata to be value of the selected item. E.g you'd need to&amp;nbsp;be able to pass the value of the selected item so that it is posted back to the server, so that RadioButtonList "recognizes" it to be a selection and changes for example the selected item and raises SelectedIndexChanged event. 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Customizing RadioButtonList</title><link>http://forums.asp.net/thread/1614223.aspx</link><pubDate>Sat, 10 Mar 2007 04:53:36 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1614223</guid><dc:creator>aivanoff</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1614223.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=1614223</wfw:commentRss><description>&lt;p&gt;I am trying to develop a server control which behaves like RadioButtonList but uses div or span instead of RadioButton. I tried to inherit RadioButtonList and override RenderItem but ran into a problem when SelectedIndexChanged stops firing.&lt;/p&gt;
&lt;p&gt;I wonder if RadioButtonList can even be extended in this way. And if not what are my other choices?&lt;/p&gt;
&lt;p&gt;Thank you,&lt;br /&gt;Alex&lt;/p&gt;</description></item></channel></rss>