Custom CheckBox class not calling AddAttributesToRender


P

Paul L

I have created a very simple WebControl which derives from the standard
CheckBox control. I want to add an extra onclick attribute which will set a
modified flag whenever the control's state changes. However the
AddAttributesToRender doesn't seem to be called, which is very odd because
it works fine for the TextBox I have overriden.

The control is definitely being instantiated, and rendered, as my test
output is there, and I can stick a breakpoint in the Render method, but when
I stick a breakpoint in the AddAttributesToRender method I get nothing.

Any ideas? The class source is below:

[ToolboxData("<{0}:CheckBox runat=server></{0}:CheckBox>")]
public class CheckBox : System.Web.UI.WebControls.CheckBox,
Level83.IEditableControl
{
protected override void Render(HtmlTextWriter output)
{
output.Write("TEST TEST TEST");
base.Render(output);
}

protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
"alert('Hello');");
base.AddAttributesToRender (writer);
}

....
...
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top