Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.net 4 how to open an "Error" screen WEB page from a Module

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I created a module and put a ton of functions in it and now if there is an error it won't open my Error WEB page???? it works fine if the function below is in the WEB page but when I have an error in try/catch it won't work.
I can't use session variables or Response.write or Response. anything.
So how do I open a WEB page which I am passing my Error info to to pop up?
Code:
here is an example of a functions Catch
        Catch ex As Exception
            'MsgBox(ex.ToString, MsgBoxStyle.Information, "Error")
            Dim ErrorTitle As String = "Error in Module1 - sp_SOWDetermineSubmittedWeekEnd"
            Dim PageName As String = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath)
            Dim Retval As String = ErrorTrap(PageName & " - " & System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ErrorTitle)
...--------------
and this is the fucntion it is calling

    Private Function ErrorTrap(ByVal ModuleCameFrom, ByVal ErrorMesssage, ByVal ErrorTitle)

        'Session("ErrorMSG") = ErrorMesssage
        'Session("ErrorTitle") = ErrorTitle
        'global vars use since Session vars won't work in a module
        gblErrorMSG = ErrorMesssage
        gblErrorTitle = ErrorTitle
        Dim strJScript As String
        strJScript = "<script language=javascript>"
        strJScript += "window.showModalDialog('ErrorScreen.aspx',null,'height=400, width=700,status= no, resizable= no, scrollbars=no, toolbar=no,location=center,menubar=no, top=100, left=300');"
        strJScript += "</script>"
        'Response.Write(strJScript) [b][COLOR=red]>>>>> <><<< ERROR HERE [/color][/b]
    ' need to open ErrorTrap.aspx which displays an Error and Title
        'ErrorTrap = WriteToEventLog(ModuleCameFrom, ErrorMesssage, Session("UserLastName"), Session("UserFirstName")) [b][COLOR=red]>>>>> ERROR HERE can't use session vars[/color][/b]


        ErrorTrap = ""
    End Function

DougP
 

If you want to display the error message information in the modal window, the ErrorScreen code-behind will have to receive the data via a session object. The trick may be to create an error package structure, fill the message information and assign it as a session variable rather than pass as parameters to your module.

In <your modulename>:

Code:
Structure ErrorMessagePackage
    Dim ModuleCameFrom As String
    Dim ErrorMesssage As String
    Dim ErrorTitle As String
End Structure

Public Sub ErrorToTrap()
    Dim strJScript As String
    strJScript = "<script language=javascript>"
    strJScript += "window.showModalDialog('ErrorScreen.aspx',null,'height=400, width=700,status= no, resizable= no, scrollbars=no, toolbar=no,location=center,menubar=no, top=100, left=300');"
    strJScript += "</script>"
    HttpContext.Current.Response.Write(strJScript)
End Sub

In your code-behind error trapping routines, include this at the top of the code so you can create new structures
Code:
Imports <your modulename>

And you can use this in a page error routine
Code:
Dim errorPackage As New ErrorMessagePackage
With errorPackage
    .ErrorMesssage = "Something went wrong"
    .ErrorTitle = "Error Encountered"
    .ModuleCameFrom = "ModuleName"
End With
Session("ERRORMESSAGE") = errorPackage
ErrorToTrap()

The ErrorScreen code-behind can then pick apart the session variable and display as needed:

Don't forget the
Code:
Imports <your modulename>

Code:
Dim errorPackage As New ErrorMessagePackage
errorPackage = Session("ERRORMESSAGE")
Dim sb As New StringBuilder
sb.Append("Error Title: " & errorPackage.ErrorTitle & "<br />")
sb.Append("Message: " & errorPackage.ErrorMesssage & "<br />")
sb.Append("In Module: " & errorPackage.ModuleCameFrom & "<br />")
Response.Write(sb.ToString)







Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top