|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
broadcasting eventscomposite 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?
Show quote
Hide quote
"SilentCry" <silentc***@sbcglobalX.net> wrote in message sounds like you're trying to use the standard += operator in order to map to 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.. 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.
Show quote
Hide quote
"SilentCry" <silentc***@sbcglobalX.net> wrote in message yeah, i eventually figured this one out too. thanx for your help though.news:es$j5q52JHA.5728@TK2MSFTNGP03.phx.gbl... > > "SilentCry" <silentc***@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.
Wizard Control - Issue 2
Wizard Control Wizard Next Button Simple composite control fires event fires first time but not second Adding "other" data in a formview on insert and update full screen web page Grid view Re: ImageUrlEditor - why can't i find it? Re: ImageUrlEditor - why can't i find it? RE: ClientIds for individual CheckBoxes in a CheckBoxList |
|||||||||||||||||||||||