Daniel Fisher (lennybacon.com)

SOA, DATA & THE WEB

Enable clientside javascript events for the RadioButtonControl

using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace StaticDust.Web.UI.Controls
{
    [Designer(typeof(RadioButtonDesigner))]
    public class RadioButton : System.Web.UI.WebControls.RadioButton
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder);
            HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
            base.Render(htmlWriter);

            StringBuilder _javaScript = new StringBuilder();

            IEnumerator keys = this.Attributes.Keys.GetEnumerator();
            int i = 1;
            string key;
            while (keys.MoveNext())
            {
                key = (String)keys.Current;
                if(key.Substring(0,2).ToLower()=="on")
                {
                    stringBuilder.Replace(key + "=\"" + this.Attributes[key].ToString() + "\" """);
                    _javaScript.Append(key + "=\"" + this.Attributes[key].ToString() + "\" ");
                }
                i++;
            }
            stringBuilder.Replace("type=\"radio\" ""type=\"radio\" " + _javaScript.ToString());

            writer.Write(stringBuilder.ToString());
        }

    }
}

 

ASP.NET, C#

« First Build on new Notebook 1000 and 1 user »

Comments

Write a comment