proper way to respond to events in widets

Posted by Community Admin on 04-Aug-2018 17:06

proper way to respond to events in widets

All Replies

Posted by Community Admin on 07-Mar-2014 00:00

Ok, so I have been working through the creation of custom widgets and have gotten pretty good at the designer side of things.   Now I need a few hints on how to properly build out the controls themselves... specifically how to properly wire up event processing within the controls.

 So when you use Sitefinity Thunder to create a custom widget it creates an ASCX to represent the layout template, and a .CS to house all the related properties and references to the controls.   Essentially, the ASCX is just a view and the .CS can be thought of as the code-behind that drives the presentation.

Where I am getting stuck is how to respond to events that are fired from asp controls that are placed within the template .ASCX.

 For example, lets say I have a button on the template.  

<asp:Button ID="GetProducts" runat="server"  Text="Show Products" /> 

I can get a handle on that button from within the .CS file like so:

         protected virtual Button GetProducts

       
            get
           
                return this.Container.GetControl<Button>("GetProducts", true);
           
       
 
 

I was then thinking that I could, within my InitializeControls method add a reference to an onClick handler like so:

            GetProducts.OnClientClick = "GetProducts_Click";  

 But that is is for clientside scripting .... how can I wireup a serverside routine?

 thx

-Sheldon

 

Posted by Community Admin on 07-Mar-2014 00:00

Ok ... I think I have answered my own question.

  GetProducts.Click += new System.EventHandler(this.GetProducts_Click);

Will wire up the server-side code ... duuu  ... 

This thread is closed