[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

SilentCry

5/17/2009 12:36:00 PM

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?


2 Answers

SilentCry

5/23/2009 11:36:00 AM

0


"SilentCry" <silentcryX@sbcglobalX.net> wrote in message
news:OYnnMwu1JHA.3780@TK2MSFTNGP04.phx.gbl...
>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

5/23/2009 11:42:00 AM

0


"SilentCry" <silentcryX@sbcglobalX.net> wrote in message
news:es$j5q52JHA.5728@TK2MSFTNGP03.phx.gbl...
>
> "SilentCry" <silentcryX@sbcglobalX.net> wrote in message
> news:OYnnMwu1JHA.3780@TK2MSFTNGP04.phx.gbl...
>>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.