User-2092341045 posted
Hello.
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>
</span>
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.