Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Exit ASP Early


Message #1 by rg1@h... on Tue, 24 Apr 2001 19:17:31
Hello.



I have an ASP page that reads a record set from a SQL database, populates 

a list box with that record set and then creates a table (using html).



I have an error handling routine that if an error occurs, I execute a 

method that displays an error page. The problem is after calling that 

method, I want to exit early from the  starting ASP page.



Using VBScript, how can I accomplish this?



Here's my code:

<%



'Open the connection to WebPPO SQL database on PPO_2

Set cmd = Server.CreateObject("ADODB.Command")

sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

cmd.ActiveConnection = sConnection



If err.Number <> 0 Then

  ErrorRoutine.TrapError = err.Description

  err.Clear

  sErrSource = "AddGroup.asp"

  Call ErrorRoutine.ManageError(sErrSource, ErrorRoutine.ErrorDescription)

End if



%>



<html>

<head>

<title>AddGroup.asp</title>

<link rel="stylesheet" href="WebPPO.css" type="text/css">

etc.

etc.

</head>

</html>



After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.



TIA.



Rita
Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 24 Apr 2001 20:57:23 +0200
Hi Rita,



If you want it to stop, do a



         Response.End



This will prevent the page from outputting any other content.



If you want, you can also use Response.Redirect to send the user to another 

page.



         Response.Redirect ("/somePage.asp")



If you get an error while using Response.Redirect about HTTP headers, this 

is caused by the fact you have already written content to the browser. 

Check out:



         http://www.adopenstatic.com/faq/headererror.asp



to see how to fix that.



Hope this helps,



Imar





At 07:17 PM 4/24/2001 +0000, you wrote:

>Hello.

>

>I have an ASP page that reads a record set from a SQL database, populates

>a list box with that record set and then creates a table (using html).

>

>I have an error handling routine that if an error occurs, I execute a

>method that displays an error page. The problem is after calling that

>method, I want to exit early from the  starting ASP page.

>

>Using VBScript, how can I accomplish this?

>

>Here's my code:

><%

>

>'Open the connection to WebPPO SQL database on PPO_2

>Set cmd = Server.CreateObject("ADODB.Command")

>sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

>cmd.ActiveConnection = sConnection

>

>If err.Number <> 0 Then

>   ErrorRoutine.TrapError = err.Description

>   err.Clear

>   sErrSource = "AddGroup.asp"

>   Call ErrorRoutine.ManageError(sErrSource, ErrorRoutine.ErrorDescription)

>End if

>

>%>

>

>etc. etc.

>After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.

>

>TIA.

>

>Rita



Message #3 by Rita Greenberg <rg1@h...> on Tue, 24 Apr 2001 12:05:21 -0700
Thanks Imar. That's what I was looking for!



-----Original Message-----

From: Imar Spaanjaars [mailto:Imar@S...]

Sent: Tuesday, April 24, 2001 11:57 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Exit ASP Early





Hi Rita,



If you want it to stop, do a



         Response.End



This will prevent the page from outputting any other content.



If you want, you can also use Response.Redirect to send the user to another 

page.



         Response.Redirect ("/somePage.asp")



If you get an error while using Response.Redirect about HTTP headers, this 

is caused by the fact you have already written content to the browser. 

Check out:



         http://www.adopenstatic.com/faq/headererror.asp



to see how to fix that.



Hope this helps,



Imar





At 07:17 PM 4/24/2001 +0000, you wrote:

>Hello.

>

>I have an ASP page that reads a record set from a SQL database, populates

>a list box with that record set and then creates a table (using html).

>

>I have an error handling routine that if an error occurs, I execute a

>method that displays an error page. The problem is after calling that

>method, I want to exit early from the  starting ASP page.

>

>Using VBScript, how can I accomplish this?

>

>Here's my code:

><%

>

>'Open the connection to WebPPO SQL database on PPO_2

>Set cmd = Server.CreateObject("ADODB.Command")

>sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

>cmd.ActiveConnection = sConnection

>

>If err.Number <> 0 Then

>   ErrorRoutine.TrapError = err.Description

>   err.Clear

>   sErrSource = "AddGroup.asp"

>   Call ErrorRoutine.ManageError(sErrSource, ErrorRoutine.ErrorDescription)

>End if

>

>%>

>

>etc. etc.

>After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.

>

>TIA.

>

>Rita



Message #4 by "Ken Schaefer" <ken@a...> on Wed, 25 Apr 2001 15:28:14 +1000
My suggestion on this is to create a little sub that will handle this all

for you:



<%

' Code in your sub that is generating the error

If Err.Number <> 0 then

    Call subWriteError(Err.Number, Proc, Err.Description)

End If



Sub subWriteError( _

    ByVal strErrNum, _

    ByVal strSource, _

    ByVal strDescrip _

    )



    Response.Clear

    Call subWritePageHeader()

    Response.Write("An error occurred. The details are:<br>" & vbCrLf)

    Response.Write("Err Number: " & strErrNum & "<br>" & vbCrLf)

    Response.Write("Err Source: " & strSource & "<br>" & vbCrLf)

    Response.Write("Err Description: & strDescrip & vbCrLf)

    Call subWritePageFooter()

    Response.Flush

    Response.End



End Sub ' subWriteError

%>



The subWriteError sub will .Flush the current cache (ie ditch anything that

you've already generated), then call your subs to write your page's header

info. You then write the error message, source and description to the page,

write your page footer, flush the Response.Buffer, and then end processing

of the page.



Cheers

Ken









~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

: Thanks Imar. That's what I was looking for!

:

: -----Original Message-----

: From: Imar Spaanjaars [mailto:Imar@S...]

: Sent: Tuesday, April 24, 2001 11:57 AM

: To: ASP Web HowTo

: Subject: [asp_web_howto] Re: Exit ASP Early

:

:

: Hi Rita,

:

: If you want it to stop, do a

:

:          Response.End

:

: This will prevent the page from outputting any other content.

:

: If you want, you can also use Response.Redirect to send the user to

another

: page.

:

:          Response.Redirect ("/somePage.asp")

:

: If you get an error while using Response.Redirect about HTTP headers, this

: is caused by the fact you have already written content to the browser.

: Check out:

:

:          http://www.adopenstatic.com/faq/headererror.asp

:

: to see how to fix that.

:

: Hope this helps,

:

: Imar

:

:

: At 07:17 PM 4/24/2001 +0000, you wrote:

: >Hello.

: >

: >I have an ASP page that reads a record set from a SQL database, populates

: >a list box with that record set and then creates a table (using html).

: >

: >I have an error handling routine that if an error occurs, I execute a

: >method that displays an error page. The problem is after calling that

: >method, I want to exit early from the  starting ASP page.

: >

: >Using VBScript, how can I accomplish this?

: >

: >Here's my code:

: ><%

: >

: >'Open the connection to WebPPO SQL database on PPO_2

: >Set cmd = Server.CreateObject("ADODB.Command")

: >sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

: >cmd.ActiveConnection = sConnection

: >

: >If err.Number <> 0 Then

: >   ErrorRoutine.TrapError = err.Description

: >   err.Clear

: >   sErrSource = "AddGroup.asp"

: >   Call ErrorRoutine.ManageError(sErrSource,

ErrorRoutine.ErrorDescription)

: >End if

: >

: >%>

: >

: >etc. etc.

: >After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.

: >

: >TIA.

@p2p.wrox.com



Message #5 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 25 Apr 2001 10:11:40 +0100
either



response.write "<meta http-equiv='refresh' content='0;url=newasp.asp'>"



or if you have 



response.buffer = true



at the top of your page, you can do



response.clear

response.redirect "newasp.asp"



-----Original Message-----

From: rg1@h... [mailto:rg1@h...]

Sent: Tuesday, April 24, 2001 8:18 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Exit ASP Early





Hello.



I have an ASP page that reads a record set from a SQL database, populates 

a list box with that record set and then creates a table (using html).



I have an error handling routine that if an error occurs, I execute a 

method that displays an error page. The problem is after calling that 

method, I want to exit early from the  starting ASP page.



Using VBScript, how can I accomplish this?



Here's my code:

<%



'Open the connection to WebPPO SQL database on PPO_2

Set cmd = Server.CreateObject("ADODB.Command")

sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

cmd.ActiveConnection = sConnection



If err.Number <> 0 Then

  ErrorRoutine.TrapError = err.Description

  err.Clear

  sErrSource = "AddGroup.asp"

  Call ErrorRoutine.ManageError(sErrSource, ErrorRoutine.ErrorDescription)

End if



%>



<html>

<head>

<title>AddGroup.asp</title>

<link rel="stylesheet" href="WebPPO.css" type="text/css">

etc.

etc.

</head>

</html>



After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.



TIA.



Rita

________________________________________________________________________

Scottish Enterprise Network

http://www.scottish-enterprise.com

Message #6 by Rita Greenberg <rg1@h...> on Wed, 25 Apr 2001 08:05:22 -0700
Hi Ken.



Thanks for the great example. I landed up using Response.Buffer = True and

then clearing and ending it as suggested.



Rita



-----Original Message-----

From: Ken Schaefer [mailto:ken@a...]

Sent: Tuesday, April 24, 2001 10:28 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Exit ASP Early





My suggestion on this is to create a little sub that will handle this all

for you:



<%

' Code in your sub that is generating the error

If Err.Number <> 0 then

    Call subWriteError(Err.Number, Proc, Err.Description)

End If



Sub subWriteError( _

    ByVal strErrNum, _

    ByVal strSource, _

    ByVal strDescrip _

    )



    Response.Clear

    Call subWritePageHeader()

    Response.Write("An error occurred. The details are:<br>" & vbCrLf)

    Response.Write("Err Number: " & strErrNum & "<br>" & vbCrLf)

    Response.Write("Err Source: " & strSource & "<br>" & vbCrLf)

    Response.Write("Err Description: & strDescrip & vbCrLf)

    Call subWritePageFooter()

    Response.Flush

    Response.End



End Sub ' subWriteError

%>



The subWriteError sub will .Flush the current cache (ie ditch anything that

you've already generated), then call your subs to write your page's header

info. You then write the error message, source and description to the page,

write your page footer, flush the Response.Buffer, and then end processing

of the page.



Cheers

Ken









~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

: Thanks Imar. That's what I was looking for!

:

: -----Original Message-----

: From: Imar Spaanjaars [mailto:Imar@S...]

: Sent: Tuesday, April 24, 2001 11:57 AM

: To: ASP Web HowTo

: Subject: [asp_web_howto] Re: Exit ASP Early

:

:

: Hi Rita,

:

: If you want it to stop, do a

:

:          Response.End

:

: This will prevent the page from outputting any other content.

:

: If you want, you can also use Response.Redirect to send the user to

another

: page.

:

:          Response.Redirect ("/somePage.asp")

:

: If you get an error while using Response.Redirect about HTTP headers, this

: is caused by the fact you have already written content to the browser.

: Check out:

:

:          http://www.adopenstatic.com/faq/headererror.asp

:

: to see how to fix that.

:

: Hope this helps,

:

: Imar

:

:

: At 07:17 PM 4/24/2001 +0000, you wrote:

: >Hello.

: >

: >I have an ASP page that reads a record set from a SQL database, populates

: >a list box with that record set and then creates a table (using html).

: >

: >I have an error handling routine that if an error occurs, I execute a

: >method that displays an error page. The problem is after calling that

: >method, I want to exit early from the  starting ASP page.

: >

: >Using VBScript, how can I accomplish this?

: >

: >Here's my code:

: ><%

: >

: >'Open the connection to WebPPO SQL database on PPO_2

: >Set cmd = Server.CreateObject("ADODB.Command")

: >sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

: >cmd.ActiveConnection = sConnection

: >

: >If err.Number <> 0 Then

: >   ErrorRoutine.TrapError = err.Description

: >   err.Clear

: >   sErrSource = "AddGroup.asp"

: >   Call ErrorRoutine.ManageError(sErrSource,

ErrorRoutine.ErrorDescription)

: >End if

: >

: >%>

: >

: >etc. etc.

: >After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.

: >

: >TIA.

@p2p.wrox.com

Message #7 by Rita Greenberg <rg1@h...> on Wed, 25 Apr 2001 08:00:18 -0700
Thanks, Alex, for the examples. I prefer the second method but wondered

which one is the better of the two. Or is it just personal preference?



-----Original Message-----

From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]

Sent: Wednesday, April 25, 2001 2:12 AM

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Exit ASP Early





either



response.write "<meta http-equiv='refresh' content='0;url=newasp.asp'>"



or if you have 



response.buffer = true



at the top of your page, you can do



response.clear

response.redirect "newasp.asp"



-----Original Message-----

From: rg1@h... [mailto:rg1@h...]

Sent: Tuesday, April 24, 2001 8:18 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Exit ASP Early





Hello.



I have an ASP page that reads a record set from a SQL database, populates 

a list box with that record set and then creates a table (using html).



I have an error handling routine that if an error occurs, I execute a 

method that displays an error page. The problem is after calling that 

method, I want to exit early from the  starting ASP page.



Using VBScript, how can I accomplish this?



Here's my code:

<%



'Open the connection to WebPPO SQL database on PPO_2

Set cmd = Server.CreateObject("ADODB.Command")

sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

cmd.ActiveConnection = sConnection



If err.Number <> 0 Then

  ErrorRoutine.TrapError = err.Description

  err.Clear

  sErrSource = "AddGroup.asp"

  Call ErrorRoutine.ManageError(sErrSource, ErrorRoutine.ErrorDescription)

End if



%>



<html>

<head>

<title>AddGroup.asp</title>

<link rel="stylesheet" href="WebPPO.css" type="text/css">

etc.

etc.

</head>

</html>



After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.



TIA.



Rita

________________________________________________________________________

Scottish Enterprise Network

http://www.scottish-enterprise.com

Message #8 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 25 Apr 2001 16:38:11 +0100
second method would be faster as they won't have to wait for HTML to load,

but they could be staring at a blank screen for a while if there was a lot

of processing to be done in the ASP



-----Original Message-----

From: Rita Greenberg [mailto:rg1@h...]

Sent: Wednesday, April 25, 2001 4:00 PM

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Exit ASP Early





Thanks, Alex, for the examples. I prefer the second method but wondered

which one is the better of the two. Or is it just personal preference?



-----Original Message-----

From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]

Sent: Wednesday, April 25, 2001 2:12 AM

To: ASP Web HowTo

Subject: [asp_web_howto] RE: Exit ASP Early





either



response.write "<meta http-equiv='refresh' content='0;url=newasp.asp'>"



or if you have 



response.buffer = true



at the top of your page, you can do



response.clear

response.redirect "newasp.asp"



-----Original Message-----

From: rg1@h... [mailto:rg1@h...]

Sent: Tuesday, April 24, 2001 8:18 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Exit ASP Early





Hello.



I have an ASP page that reads a record set from a SQL database, populates 

a list box with that record set and then creates a table (using html).



I have an error handling routine that if an error occurs, I execute a 

method that displays an error page. The problem is after calling that 

method, I want to exit early from the  starting ASP page.



Using VBScript, how can I accomplish this?



Here's my code:

<%



'Open the connection to WebPPO SQL database on PPO_2

Set cmd = Server.CreateObject("ADODB.Command")

sConnection = "DSN=myDSN;UID=myUID;PWD=myPWD;"

cmd.ActiveConnection = sConnection



If err.Number <> 0 Then

  ErrorRoutine.TrapError = err.Description

  err.Clear

  sErrSource = "AddGroup.asp"

  Call ErrorRoutine.ManageError(sErrSource, ErrorRoutine.ErrorDescription)

End if



%>



<html>

<head>

<title>AddGroup.asp</title>

<link rel="stylesheet" href="WebPPO.css" type="text/css">

etc.

etc.

</head>

</html>



After the "Call ErrorRoutine.ManageError(etc.) I want to leave that ASP.



TIA.



Rita

________________________________________________________________________

Scottish Enterprise Network

http://www.scottish-enterprise.com


  Return to Index