User-266787045 posted
Hi,
i have a fired event problem in a web custom control, that code works with Visual Studio 2003 / framework 1.1.
But if i migrate the same code in Visual Studio 2005 / framework 2.0 it doesn't work.
The webform where i import the control can't catch the event "Conferma_Click_Event". [:(]
Any solution?
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Ave
{
[ToolboxData("<{0}:CustomButton runat=server></{0}:CustomButton>")]
public class CustomButton : WebControl
{
PlaceHolder oPlaceHolder = new PlaceHolder();
Button oButton = new Button();
// * OGGETTI EVENTO *
private static readonly object Conferma_Click_Event = new object();
[
Category("Action"),
Description("Evento scatenato al Click del bottone Conferma")
]
public event EventHandler Conferma_Click
{
add
{
Events.AddHandler(Conferma_Click_Event, value);
}
remove
{
Events.RemoveHandler(Conferma_Click_Event, value);
}
}
public CustomButton()
{
CreateChildControls();
}
protected override void CreateChildControls()
{
oPlaceHolder.Controls.Clear();
oButton.Click += new EventHandler(ConfermaOnClick);
oPlaceHolder.Controls.Add(oButton);
this.Controls.Add(oPlaceHolder);
}
private void ConfermaOnClick(object sender, EventArgs e)
{
if (Events != null)
{
EventHandler Evento = (EventHandler)(Events[Conferma_Click_Event]);
if (Evento != null)
{
Evento(sender, e);
}
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
}
}