Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:42:48+00:00 2026-06-14T05:42:48+00:00

I have a large .aspx page, with multiple server controls. And, there is also

  • 0

I have a large .aspx page, with multiple server controls. And, there is also a JavaScript file referenced by this .aspx page. I want to have a JavaScript function within this existing .js file, that will get called before any postback that happens to the server.

[note: I have seen another post that mention how to do this in JQuery ( How to capture submit event using jQuery in an ASP.NET application? ), but I would like that to be done through the existing JavaScript file, rather than using a new technology like JQuery]

[Edited] Solution of using OnSubmit handler will not work for me…because it will not get called for postbacks that get triggered by server controls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:42:50+00:00Added an answer on June 14, 2026 at 5:42 am

    You need something like this:

    /* 
       usually there is only one form in asp.net, but if you know you can have 
       more than one, you can get main form with document.getElementById
    */
    var form = document.getElementsByTagName("form")[0];     
    if (form.addEventListener) {
        form.addEventListener('submit', functionThatShouldBeCalledBeforeSubmit, false); 
    } else if (form.attachEvent)  {
        form.attachEvent('onsubmit', functionThatShouldBeCalledBeforeSubmit);
    }
    

    onsubmit event will rise any time form is submitted. No matter how.

    More details about attaching events with JS: https://developer.mozilla.org/en-US/docs/DOM/element.addEventListener

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, if I have a page located in Views/Home/Index.aspx and a JavaScript file
Suppose someone: visits and ASPX page (http get request). sets a too large file
Currently, I have got 7 user controls placed on a single aspx page, some
So we have this tool, it's a web page, we drop a large piece
Here's the JavaScript (on an aspx page): function WriteDocument(clientRef, system, branch, category, pdfXML) {
I have a large html file that I want to split apart. I have
I have an aspx page where i am Processing a large number of records
I have large set of flow charts and workflow diagrams. I want to draw
I have a dynamically generated CSS file. It's fairly large, and has different content
I have a asp.net download page which send a file to client but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.