broadcasting events

Discussion in 'ASP .Net Web Controls' started by SilentCry, May 17, 2009.

  1. SilentCry

    SilentCry Guest

    i have a solution that contains 2 projects - a class library project for my
    composite control and a web project i use to test the control. that is i use
    default.aspx as a container for the control which i add via the toolbar in
    design mode.
    my composite control has 2 buttons on it both of which i can trap the click
    event of via the OnBubbleEvent handler (overriden). this all takes place
    within the scope of the composite control code. one of the buttons does a
    save of a textboxes content to a file on the client side but the code i'm
    using (below) can only be placed in default.aspx not in the control. also, i
    only want to do this when the button is clicked..

    Response.ContentType = "application/xml";
    Response.RedirectLocation = SaveFileName;
    Response.AddHeader("Content-Disposition",
    "attachment;filename=\"" + SaveFileName + "\"");
    Response.Write(e.XML);
    Response.End();

    so basically i need to know how to bubble or broadcast the click event of
    the Save button up to the containing page. being that the control itself is
    in a different project than the page, i can't just use the name of the pages
    handler/method in the control project because it's not recognized.
    any ideas? or maybe there's a better way to do this?
     
    SilentCry, May 17, 2009
    #1
    1. Advertising

  2. SilentCry

    SilentCry Guest

    "SilentCry" <> wrote in message
    news:...
    >i have a solution that contains 2 projects - a class library project for my
    >composite control and a web project i use to test the control. that is i
    >use default.aspx as a container for the control which i add via the toolbar
    >in design mode.
    > my composite control has 2 buttons on it both of which i can trap the
    > click event of via the OnBubbleEvent handler (overriden). this all takes
    > place within the scope of the composite control code. one of the buttons
    > does a save of a textboxes content to a file on the client side but the
    > code i'm using (below) can only be placed in default.aspx not in the
    > control. also, i only want to do this when the button is clicked..
    >
    > Response.ContentType = "application/xml";
    > Response.RedirectLocation = SaveFileName;
    > Response.AddHeader("Content-Disposition",
    > "attachment;filename=\"" + SaveFileName + "\"");
    > Response.Write(e.XML);
    > Response.End();
    >
    > so basically i need to know how to bubble or broadcast the click event of
    > the Save button up to the containing page. being that the control itself
    > is in a different project than the page, i can't just use the name of the
    > pages handler/method in the control project because it's not recognized.
    > any ideas? or maybe there's a better way to do this?
    >
    >

    hey SC..
    sounds like you're trying to use the standard += operator in order to map to
    the handler method to the event where you would have to know the name of it.
    don't need to. all you have to do is expose your control's event so that it
    shows up in the properties box in design mode when clicking on the lightning
    bolt. to do this you have to use an event 'property'..

    public delegate void SaveXmlEventHandler(object sender,
    SaveXmlEventArgs e);
    private static readonly object SaveXmlEventKey = new object();

    public event SaveXmlEventHandler SaveXml // <<<--- event property
    {
    add { Events.AddHandler(SaveXmlEventKey, value); }
    remove { Events.RemoveHandler(SaveXmlEventKey, value); }
    }

    protected virtual void OnSaveXml(SaveXmlEventArgs e)
    {
    SaveXmlEventHandler handler = Events[SaveXmlEventKey] as
    SaveXmlEventHandler;

    if (handler != null)
    handler(this, e);
    }

    this is all you need. you would just call OnSaveXml at the point you want
    the event to fire.
    as far as handling the event in your containing app, bring up the page, go
    into properties, click on the lightning bolt, then find and double click on
    SaveXml. this will generate the event handler in your pages code behind. you
    can then insert all your Response stuff.
     
    SilentCry, May 23, 2009
    #2
    1. Advertising

  3. SilentCry

    SilentCry Guest

    "SilentCry" <> wrote in message
    news:es$...
    >
    > "SilentCry" <> wrote in message
    > news:...
    >>i have a solution that contains 2 projects - a class library project for
    >>my composite control and a web project i use to test the control. that is
    >>i use default.aspx as a container for the control which i add via the
    >>toolbar in design mode.
    >> my composite control has 2 buttons on it both of which i can trap the
    >> click event of via the OnBubbleEvent handler (overriden). this all takes
    >> place within the scope of the composite control code. one of the buttons
    >> does a save of a textboxes content to a file on the client side but the
    >> code i'm using (below) can only be placed in default.aspx not in the
    >> control. also, i only want to do this when the button is clicked..
    >>
    >> Response.ContentType = "application/xml";
    >> Response.RedirectLocation = SaveFileName;
    >> Response.AddHeader("Content-Disposition",
    >> "attachment;filename=\"" + SaveFileName + "\"");
    >> Response.Write(e.XML);
    >> Response.End();
    >>
    >> so basically i need to know how to bubble or broadcast the click event of
    >> the Save button up to the containing page. being that the control itself
    >> is in a different project than the page, i can't just use the name of the
    >> pages handler/method in the control project because it's not recognized.
    >> any ideas? or maybe there's a better way to do this?
    >>
    >>

    > hey SC..
    > sounds like you're trying to use the standard += operator in order to map
    > to the handler method to the event where you would have to know the name
    > of it. don't need to. all you have to do is expose your control's event so
    > that it shows up in the properties box in design mode when clicking on the
    > lightning bolt. to do this you have to use an event 'property'..
    >
    > public delegate void SaveXmlEventHandler(object sender,
    > SaveXmlEventArgs e);
    > private static readonly object SaveXmlEventKey = new object();
    >
    > public event SaveXmlEventHandler SaveXml // <<<--- event
    > property
    > {
    > add { Events.AddHandler(SaveXmlEventKey, value); }
    > remove { Events.RemoveHandler(SaveXmlEventKey, value); }
    > }
    >
    > protected virtual void OnSaveXml(SaveXmlEventArgs e)
    > {
    > SaveXmlEventHandler handler = Events[SaveXmlEventKey] as
    > SaveXmlEventHandler;
    >
    > if (handler != null)
    > handler(this, e);
    > }
    >
    > this is all you need. you would just call OnSaveXml at the point you want
    > the event to fire.
    > as far as handling the event in your containing app, bring up the page, go
    > into properties, click on the lightning bolt, then find and double click
    > on SaveXml. this will generate the event handler in your pages code
    > behind. you can then insert all your Response stuff.

    yeah, i eventually figured this one out too. thanx for your help though.
     
    SilentCry, May 23, 2009
    #3
    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. valentin tihomirov

    broadcasting a signal

    valentin tihomirov, Sep 22, 2004, in forum: VHDL
    Replies:
    11
    Views:
    741
    Jim Lewis
    Sep 23, 2004
  2. Fax Broadcasting

    , Sep 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    467
    Lucas Tam
    Sep 25, 2005
  3. =?Utf-8?B?S2VubnkgTS4=?=

    broadcasting a live conference

    =?Utf-8?B?S2VubnkgTS4=?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    =?Utf-8?B?S2VubnkgTS4=?=
    Apr 4, 2006
  4. RipW
    Replies:
    1
    Views:
    352
    Neredbojias
    Aug 10, 2005
  5. BigZero

    Broadcasting,Need Help.....!

    BigZero, Mar 3, 2008, in forum: Java
    Replies:
    2
    Views:
    354
    BigZero
    Mar 3, 2008
Loading...

Share This Page