locked
Customizing RadioButton Control RRS feed

  • Question

  • User764522383 posted

    Im Customizing RadioControl Button but I cant set the Text Property for the Control?

    How Should I set the Text for Radiobutton Control ? In  HtmlTextWriterAttribute class there isnt any property for Text.

    I set  OverridedRadioButton.Text = "new Text" but there is nothing on the page same for OverridedRadioButton.ForeColor .....

    how should I Override these two Properties?

    **********************************************************************

    protected override void Render(HtmlTextWriter output)
            {
                RenderInputTag(output);
            }


            private void RenderInputTag(HtmlTextWriter htw)
            {
                htw.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
                htw.AddAttribute(HtmlTextWriterAttribute.Type, "radio");
                htw.AddAttribute(HtmlTextWriterAttribute.Name, GroupName);
                htw.AddAttribute(HtmlTextWriterAttribute.Value, Value);
                if (Checked)
                    htw.AddAttribute(HtmlTextWriterAttribute.Checked, "checked");
                if (!Enabled)
                    htw.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");

                string onClick = Attributes["onclick"];
                if (AutoPostBack)
                {
                    if (onClick != null)
                        onClick = String.Empty;
                    onClick += Page.GetPostBackClientEvent(this, String.Empty);
                    htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
                    htw.AddAttribute("language", "javascript");
                }
                else
                {
                    if (onClick != null)
                        htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
                }

                if (AccessKey.Length > 0)
                    htw.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
                if (TabIndex != 0)
                    htw.AddAttribute(HtmlTextWriterAttribute.Tabindex,
                        TabIndex.ToString(NumberFormatInfo.InvariantInfo));
                htw.RenderBeginTag(HtmlTextWriterTag.Input);
                htw.RenderEndTag();
            }

            #endregion

     

     

    Thursday, June 12, 2008 8:31 AM

Answers

  • User1876077875 posted

    <input type="radio" /> doesn't support text attribute (the same is for a checkbox).

    To add a text to a radiobutton the generated HTML markup should look like this:

    <input type="radio" id="radio1" /><label for="radio1">RadioButton</label>
     Color styles should be applied to the label as well and not to the input tag. 
     
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 12, 2008 9:02 AM

All replies

  • User1876077875 posted

    <input type="radio" /> doesn't support text attribute (the same is for a checkbox).

    To add a text to a radiobutton the generated HTML markup should look like this:

    <input type="radio" id="radio1" /><label for="radio1">RadioButton</label>
     Color styles should be applied to the label as well and not to the input tag. 
     
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 12, 2008 9:02 AM
  • User764522383 posted

    "mCodl " BTW  THanks for your replay

    Monday, June 16, 2008 3:28 AM