Calling a web page from within a class module. RRS feed

  • Question

  • User-2039444100 posted

    I have been given an ASP.Net assignment at work because I had taken a few courses a couple of years ago. Currently, there are no ASP.Net programmers for me to ask here and I have searched several places (including Pro ASP Net book) to find a solution but have come up empty handed.

    Here is my problem. I have a class named spErrors which takes the values passed to it. Values passed include the offending page, function/sub, and other values and stores them in property values, then calls Response.Redirect("Errors.aspx") from the page's code behind page. In Errors.aspx, the values of the error/exception trapped in the Catch statement are displayed. This works fine from a web form. My question is, how do I call a web page from a class module?

    Each class module has the ErrorHandler() procedure that passes these values to the class object. In the class, there is a Write Only property named Redirect and  a method called Execute() which is used to display the error page if the error occurs in another class module. Since Response.Redirect() does not work in a class module, what namespace is needed in order for this to work?

    Here is the code I'm using.

    In the Catch block.

    Catch ex As Exception
       Err.Description = ex.Message
       ErrorHandler(Err, "function name")
       ' other code here if needed
    End Try

    The ErrorHandler procedure:

    Private Shared Sub ErrorHandler(ByVal Err As ErrObject, ByVal Section As String, Optional ByVal Icon As Int32 = 0)

       If Icon = 0 Then Icon = vbExclamation
       spErrors.ErrMsg = Err.Description
       spErrors.ErrPage =
       spErrors.ErrSection = Section
       spError.IconType = Icon
       spErrors.WebPageName =
       Response.Redirect("Errors.aspx")             'This line is used on when the function is in a code behind page.
       spErrors.Redirect =
    "Errors.aspx"              'Property used for class modules only
       spErrors.Execute()                                   'Method used for class modules only

    End Sub

     The Execute() method is where I am having my problems.




    Monday, June 1, 2009 10:59 AM

All replies

  • User1902359598 posted

    You can actually access the Redirect() method from a class module through the HttpContext class and a redirection will occur like so:


    You may need to use another method within the Redirect() method to get to your Errors page depending on where is it located within your app.

    Monday, June 1, 2009 1:45 PM
  • User-2039444100 posted

    Thanks for the quick reply. I'll give that a try at work tomorrow when I have access to the database.

    Monday, June 1, 2009 5:57 PM