M
Mickie
I'm trying to create a server Web control that renders as a checkbox that
has an OnClick event associated with it. I've created a short proof of
concept to simply attach an alert message when the checkbox is clicked. The
problem is that the override is being ignored and the OnClick event is never
rendered.
If you change 'public class ctlCheckBoxSelect : CheckBox' to
'public class ctlCheckBoxSelect : Button', then it will render successfully
as a Button with the OnClick event associated with it.
Any help with ideas for how to get the OnClick event to render for the
CheckBox in this way would be greatly appreaciated.
Thanks,
- Mickie
Here is the code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace ClientSideScripts
{
/// <summary>
/// Check box that pops up an alert box when clicked.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:ctlCheckBoxSelect
runat=server></{0}:ctlCheckBoxSelect>")]
public class ctlCheckBoxSelect : CheckBox
{
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
string script = @"alert(""Hello"");";
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, script);
base.AddAttributesToRender(writer);
//this.AddAttributesToRender(writer);
}
}
}
has an OnClick event associated with it. I've created a short proof of
concept to simply attach an alert message when the checkbox is clicked. The
problem is that the override is being ignored and the OnClick event is never
rendered.
If you change 'public class ctlCheckBoxSelect : CheckBox' to
'public class ctlCheckBoxSelect : Button', then it will render successfully
as a Button with the OnClick event associated with it.
Any help with ideas for how to get the OnClick event to render for the
CheckBox in this way would be greatly appreaciated.
Thanks,
- Mickie
Here is the code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace ClientSideScripts
{
/// <summary>
/// Check box that pops up an alert box when clicked.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:ctlCheckBoxSelect
runat=server></{0}:ctlCheckBoxSelect>")]
public class ctlCheckBoxSelect : CheckBox
{
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
string script = @"alert(""Hello"");";
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, script);
base.AddAttributesToRender(writer);
//this.AddAttributesToRender(writer);
}
}
}