Checkbox control is not firing RenderBeginTag RRS feed

  • Question

  • User-2092341045 posted


    I'm to add some custom attributes to a custom checkbox control, but I'm getting stuck because the base CheckBox control is behaving weird (I guess).

    I tested several ways to add the attribute, but for this post I'll say that RenderBeginTag() is not being executed. See:

        public class CheckBox : System.Web.UI.WebControls.CheckBox
            public override void RenderBeginTag(HtmlTextWriter writer)
                base.RenderBeginTag(writer); // <== NOTE: I added a breakpoint here
                writer.WriteAttribute("MyAttribute", "someValue");

    Note I added a breakpoint to check if it is working. It is not! When I run the page hosting the control, the process never breaks in the breakpoint I defined.

    NOTE 1: To test if I'm not crazy, I added the breakpoints to another overrides, and it works well. The only overrides I noticed are not working are RenderBeginTag() and RenderEndTag().

    NOTE 2: This issue happen only with CheckBox. Buttons, for example, are working fine in my tests.

    NOTE 3: AddAttributesToRender() also don't work for the CheckBox, because it is producing a span tag out of the control. See:

        <span MyAttribute="someValue">
            <input id="CheckBox2" type="checkbox" name="CheckBox2" />
            <label for="CheckBox2">MyCheckBox</label>


    Do you know how can I add my custom attributes to my custom CheckBox, like the sample below?

        <input id="CheckBox2" type="checkbox" name="CheckBox2" MyAttribute="someValue" />

    I hope I dont need to full override the RenderControl(), hehe. I want to enjoy all the working features of CheckBox control.

    Wednesday, March 19, 2008 12:46 PM


  • User-865881720 posted

    Because the CheckBox control itself overrides the Render method, RenderBeginTag, RenderContents, RenderEndTag will never be called.  You would have to override Render but I seem to recall that it is declared with Friend scope.  I'd suggest you take a look at the Render code using Lutz Roeder's .Net Reflector.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 19, 2008 6:12 PM