Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > broadcasting events

Reply
Thread Tools

broadcasting events

 
 
SilentCry
Guest
Posts: n/a
 
      05-17-2009
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?


 
Reply With Quote
 
 
 
 
SilentCry
Guest
Posts: n/a
 
      05-23-2009

"SilentCry" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.

 
Reply With Quote
 
 
 
 
SilentCry
Guest
Posts: n/a
 
      05-23-2009

"SilentCry" <(E-Mail Removed)> wrote in message
news:es$(E-Mail Removed)...
>
> "SilentCry" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
broadcasting SSID Sam Wireless Networking 19 11-18-2004 12:49 AM
ssid broadcasting from my netgear router Craig Wireless Networking 4 10-08-2004 03:09 AM
broadcasting a signal valentin tihomirov VHDL 11 09-23-2004 07:36 PM
New Data Broadcasting Forum File Xfer Wireless Networking 0 09-10-2004 04:46 AM



Advertisments