I need to create a payment gateway user control that will be used accross all of the modules. This user control should be as simple as doing the transaction ONLY. So what I need to do is to let the host/page container knows whether the transaction is succeeded or not, if it is succeeded then the rest of the logic will be handled on ASPX page.
In order to do so I need to create an event on the user control that will be bubbled up to the page container/host. This sample might not be the best solution but it works perfectly for my needs and only requires several lines of code.
Write this in your user control including declaration(signature) of parameter that you want to pass
Partial Class usercontrols_MyPaymentGateway Inherits System.Web.UI.UserControl #Region "Property" '''''' this is an event for process status ''' ''' Public Event getProcessStatus(ByVal isPaid As Boolean)
Write this in your user control where you want to raise the event and pass the parameter
RaiseEvent getProcessStatus(True)
Write this in your page container(Create an Event handler to handle your user control events) (NOTE: paymentGateway is the name of your user control)
'''''' event handler to the payment gateway controls ''' ''' ''' Private Sub paymentProcessed(ByVal isPaid as boolean) Handles paymentGateway.getProcessStatus If (paymentGateway.IsPaid) Then ltMessage.Text = "Payment Successful " + paymentGateway.ResponseMessage 'if it is paid then we need to clear the remaining text boxes paymentGateway.ClearFields() Else ltMessage.Text = "Payment Failed " + paymentGateway.ResponseMessage End If End Sub
Leave a Reply