views:

53

answers:

1

I have some couple of events like when user subscribes to my newsletter it fires a subscribed event so that an e-mail will be sent to corresponding users to notify them about their subscriptions. But where should I handle those events ? What is the best practice to handle events ? Should I bind event handlers to events in Subscribe Button click event or should I use Global.Asax Application_Start event to begin listening my newsletter subscription events ?

Thanks.

+2  A: 

It really depends on your usage scenario. E.g. the frequency of subscribes, the timing of the notification.

A straight-forward can will be, you have a reasonable subscription frequency which your server can handle each notification individually (synchronously) and you want to notify them as soon as they subscribe.

Code your notification function as an independent one outside the scope of the page(s) that accept the subscription. Reason being you can then reuse them in out pages/controls.

A simple one is to place the code in "/app-code" folder.

Fire the function from your on_click event of any subscription button you have created.

I assume you will perform the necessary validations and return an appropriate response.

I will not go into other scenario if the above suffice you needs.

o.k.w