broadcasting events

S

SilentCry

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?
 
S

SilentCry

SilentCry said:
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.
 
S

SilentCry

SilentCry said:
SilentCry said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top