devxlogo

Automatically Calling a Function When a Page Ends

Automatically Calling a Function When a Page Ends

Question:
Is there any way to call a function automatically when an ASP page ends? I know about Application_OnEnd and Session_OnEnd but isn’t there any “Page_OnEnd” function or some way of simulating it?

Answer:
The key here is what you mean by “when an ASP page ends.” If you are talking about server-side processing, just place your code or a call to your function at the very bottom of your page. Assuming that there is no other branching, it will be the last piece of code to be executed before the server ends processing your page.

If you are talking about code to be executed when your site visitor leaves your HTML page, then put a call to your CLIENT SIDE JavaScript, JScript or VBScript code in the ONUNLOAD event of the body tag, such as this:

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist