Intercept when my control dropped on a WebForm

Discussion in 'ASP .Net Building Controls' started by Vipeo, Jan 12, 2006.

  1. Vipeo

    Vipeo Guest

    Hi All!

    I need to intercept the event when my control dropped on a WebForm (or
    manually added by changin page's source HTML). I know about
    IComponentChangeService and its ComponentAdding event, but in which class
    should I use it?

    Thank you for any help.
    Vipeo, Jan 12, 2006
    #1
    1. Advertising

  2. Vipeo

    Vipeo Guest

    Sorry, figured this out.

    "Vipeo" wrote:

    > Hi All!
    >
    > I need to intercept the event when my control dropped on a WebForm (or
    > manually added by changin page's source HTML). I know about
    > IComponentChangeService and its ComponentAdding event, but in which class
    > should I use it?
    >
    > Thank you for any help.
    Vipeo, Jan 12, 2006
    #2
    1. Advertising

  3. Vipeo

    Ian Guest

    Could you post it here then?
    Ian, Jan 12, 2006
    #3
  4. Vipeo

    Vipeo Guest

    To get this "extra" functionality in design-time for your control, you need
    to have a designer (System.Wen.UI.Design.ControlDesigner), and don't forget
    to apply the DesignerAttribute to your control. The designer's code requests
    a IComponentChangeService and subscribes to its ComponentAdding event. That's
    all.

    So, in my case the designer looks like this:

    class CMSWebPageDesigner : ControlDesigner
    {
    private IComponentChangeService changeService = null;

    private void InitializeServices()
    {
    this.changeService = GetService(typeof(IComponentChangeService))
    as IComponentChangeService;
    if (changeService != null)
    {
    changeService.ComponentAdding += new
    ComponentEventHandler(ChangeService_ComponentAdding);
    }
    }

    void ChangeService_ComponentAdding(object sender, ComponentEventArgs
    e)
    {
    if (e.Component is CMSWebPage)
    throw new ApplicationException("CMSWebPage component is
    already on the page.");
    }

    #region Overrides

    public override bool AllowResize
    {
    get
    {
    return false;
    }
    }

    private DesignerVerbCollection designTimeVerbs;
    public override DesignerVerbCollection Verbs
    {
    get
    {
    if (null == designTimeVerbs)
    {
    designTimeVerbs = new DesignerVerbCollection();
    designTimeVerbs.Add(new DesignerVerb("Page Setup...",
    new EventHandler(this.OnPageSetup)));
    }
    return designTimeVerbs;
    }
    }

    protected override void Dispose(bool disposing)
    {
    if (disposing)
    {
    if (this.changeService != null)
    {
    // Unhook event handlers.
    this.changeService.ComponentAdding -=
    new ComponentEventHandler(
    ChangeService_ComponentAdding);
    }
    }

    base.Dispose(disposing);
    }

    public override void Initialize(IComponent component)
    {
    if (!(component is CMSWebPage))
    throw new ArgumentException("Must be a CMSWebPage component");
    base.Initialize(component);

    InitializeServices();
    }

    #endregion

    private void OnPageSetup(object sender, EventArgs e)
    {
    PageDesignerEditor editor = new PageDesignerEditor();
    editor.EditComponent(Component);
    }
    }


    "Ian" wrote:

    > Could you post it here then?
    >
    >
    Vipeo, Jan 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. titof
    Replies:
    0
    Views:
    490
    titof
    Jul 24, 2003
  2. James J. Foster
    Replies:
    0
    Views:
    519
    James J. Foster
    Aug 7, 2003
  3. A Traveler

    Init Control when dropped on form??

    A Traveler, Oct 23, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    524
    WALDO
    Oct 25, 2004
  4. JohnnyV

    Custom Control not dropped on web page

    JohnnyV, Feb 9, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    91
    JohnnyV
    Feb 11, 2004
  5. A Traveler

    Init Control when dropped on form??

    A Traveler, Oct 23, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    171
    A Traveler
    Oct 25, 2004
Loading...

Share This Page