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 1058265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:00:00+00:00 2026-05-16T18:00:00+00:00

net usercontrol located on on my aspx page. In the usercontrol there is a

  • 0

net usercontrol located on on my aspx page. In the usercontrol there is a javascript function that I would like to fire everytime the page that contains the usercontrol submits to the server. (directly before this happens) Ideally I prefer to not have to write any code in the parent to make this happen, but I am not sure what the usercontrol may be capable of at this time. Can the usercontrol know that the page is submitting to the server and fire the function before this happens? Is there some sort of event that takes place here?

Is this possible? And is my description clear?

Thanks!

  • 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-05-16T18:00:00+00:00Added an answer on May 16, 2026 at 6:00 pm

    you can add a client side event handler for the form’s submit event. you can generate your javascript when Page_Load is called in the user control and use Page.ClientScript.RegisterStartupScript to add it to the page.

    string key = "submitscript";
    
    System.Text.StringBuilder script = new System.Text.StringBuilder();
    script.Append("function mySubmitHandler(e) { \n");
    script.Append("    // TODO my javascript here \n");
    script.Append("    alert('derp'); \n");
    script.Append("} \n");
    script.AppendFormat("var f = document.getElementById('{0}'); \n", Page.Form.ClientID);
    script.Append("if(f.addEventListener){\n");
    script.Append("    f.addEventListener('submit', mySubmitHandler, false); \n");
    script.Append("} else { \n");
    script.Append("    f.attachEvent('onsubmit', mySubmitHandler); \n");
    script.Append("} \n");
    
    Page.ClientScript.RegisterStartupScript(this.GetType(), key, script.ToString(), true);
    

    the script will only be added once for each combination of the type and key parameters, so you can have multiple user controls on the page and this script will only be added once.

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

Sidebar

Related Questions

I have a usercontrol that is in an asp.net page that contains a button.
I have asp.net usercontrol that is including some js script like this <script type=text/javascript
Suppose I have javascript within ASP.NET UserControl: function setValue(DataItem) { var selectedDate = DataItem.getMember('DomainNameKey').get_object();
I would like to know if it is possible to cache an ASP.NET UserControl
I am using the Asp.net OutputCache on a page containing a usercontrol that in
I have an asp.net usercontrol that contains a jQuery UI Dialog Control. All works
I have an ASP.Net UserControl that looks like this: <%@ Control Language=C# AutoEventWireup=true CodeBehind=WebUserControl1.ascx.cs
I have an ASP.NET usercontrol that implements the ValidationProperty attribute. This attribute successfully makes
I have an asp.net UserControl that writes HTML content from a SharePoint list to
I make a asp.net usercontrol. its name is ucTreeview. in my page it named:

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.