locked
Web custom control fired event problem RRS feed

  • Question

  • 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("&lt;{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);
    }
    }
    }
    Thursday, June 26, 2008 5:08 AM

Answers

  • User-1772909511 posted

    Sometimes giving id to the controls will work.

    Try with Implementing INamingContainer.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2008 5:49 AM

All replies

  • User-1772909511 posted

    Sometimes giving id to the controls will work.

    Try with Implementing INamingContainer.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2008 5:49 AM
  • User-266787045 posted

     thank you very much. it works ........ [;)]

    Thursday, June 26, 2008 5:55 AM