Solved

How to trigger functions in asp.net/vb.net

Posted on 2009-07-15
4
682 Views
Last Modified: 2013-11-08

Hi

I have myhandler.ashx file and which has code behind file  at "app_code/myhandler.ashx.vb" .
myhandler.ashx file  will be triggered by some external process.

in myhandler.ashx file , i write below code:
perform

Public Class PaypalColorHandler : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                   
                    Case Is = "XYZ"
                        //execute some logic to handle transaction "XYZ"

                   CAse Is=""ABC"
                       //execute logic to handle transaction "ABC"
   etc..



     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
 

I want to write generic class to handle above to re-use above accross the projects.

i am thinking to write like this,
   i wanto create "generichandler.vb" handler which other devlopers can call .
  Devopers still create their own .ashx file with own code behind file(Devloperown.ashx.vb) and they still write Processrequest()  in DevloperOwn.ashx.vb.  But inside processRequest() fucintion they call "create object of generichandler" and call "handleRequest()" function.

Please let me know how to  initiate triggers in "genricHanlder.vb"  to call "ABCTrigger(),XYZTrigger() etc. also syntax for how to define functions these fucntions.
Please let me know.
alos Is it possible to write these "ABCTrigger() and XYZTrigger() " functions  inside devloperhandler(DevloperOwnHandler.ashx.vb) itself instead of writing in "genericHandler.vb" file.



Current Code: Myhandler.ashx.vb
Public Class  MyHandler: Implements IHttpHandler
 
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                    
                    Case Is = "XYZ" 
                        //execute some logic to handle transaction "XYZ"
 
                   CAse Is=""ABC"
                       //execute logic to handle transaction "ABC"
   etc..
 
 
 
     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
End Sub
 
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class
 
....
 
generichandler.vb:
 Public Class generichandler
    public sub handleRequest(ByVal context As HttpContext)
       step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                    
                    Case Is = "XYZ" 
                       // ' trigger XYZTrigger() //to perform logic for transaction "XYZ"
 
                   CAse Is=""ABC"
                     //   ' trigger ABCTrigger() //to perform logic for transaction "ABC"   etc..
 
 
 
     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
' 
  End Sub
 
public sub ABCTrigger()  
' implementation defered to devloepr to write own logic to perform database updates etc..
end sub
   End Class
 
public sub XYZTrigger()  
' implementation defered to devloepr to write own logic to perform database updates etc..
end sub
   End Class

Open in new window

0
Comment
Question by:ram27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 24863185
Maybe I totally misread, but it seems developers should inherit from your class here.  You might also need to declare some methods "MustOverride" so when they do this, they are forced to extend the functionality or it will not compile.
0
 

Author Comment

by:ram27
ID: 24865019
i mentioned in my post may not be righ
Please see below i reframed my question see below:

I have myhandler.ashx file and which has code behind file  at "app_code/myhandler.ashx.vb" .
myhandler.ashx file  will be triggered by some external process and based on the trasaction type, i want to execute different logic(will be specefic for each project) . Implementation logic for each transaction  want to defer to devlopers.
here is my code for "myhandler.ashx.vb":


Public Class myhandler: Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                   
                    Case Is = "XYZ"
                        //execute some logic to handle transaction "XYZ"

                   CAse Is=""ABC"
                       //execute logic to handle transaction "ABC"
   etc..



     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
 


Pease let me know best way to achive this.
i have below  approach in mind:
create class called "myhandler"

I want to write generic class for above (myhandler.aspx.vb) to re-use   the accross the projects.

i have below approach in mymind
" create "generichandler.vb" handler which other devlopers can call .
  Devopers still create their own .ashx and .vb files with own code behind file(Devloperown.ashx.vb) and they still write Processrequest()  in DevloperOwn.ashx.vb.  But inside processRequest() fucintion they  "create object of generichandler" and call "handleRequest()" function. in this parroach,
Please let me know how to  initiate trigger/fire events  in "genricHanlder.vb"  to call "ABCTrigger(),XYZTrigger() etc based on the transaction type. . also syntax for how to define functions these fucntions.
Please let me know.
alos Is it possible to write these "ABCTrigger() and XYZTrigger() " functions  inside devloperhandler(DevloperOwnHandler.ashx.vb) itself instead of writing in "genericHandler.vb" file.
code:
generichandler.vb:
 Public Class generichandler
    public sub handleRequest(ByVal context As HttpContext)
       step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                   
                    Case Is = "XYZ"
                       // ' trigger XYZTrigger() //to perform logic for transaction "XYZ"
 
                   CAse Is=""ABC"
                     //   ' trigger ABCTrigger() //to perform logic for transaction "ABC"   etc..
 
 
 
     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
'
  End Sub
 
public sub ABCTrigger()  
' implementation defered to devloepr to write own logic to perform database updates etc..
end sub
   End Class


Please let me know whether the above approach makes feasible or not. IS there any best approach.

0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 24865284
If you want the code handling the transaction to be specific to each project, then ditch the generichandler.vb idea and write the code within myhandler.ashx.vb.  Any other way creates unnecessary generalizaton, when in fact each handler is going to specialize for the particular set of operations necessary for the project.  This is the way I see it, based on what you've said so far.  
0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 24869297
I still go with my first suggestion.  If you have a generic plan for how something should work, and each project needs to implement these set methods, then Inheritance/Interfaces are the way to go.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question