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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:06:31+00:00 2026-05-28T05:06:31+00:00

I am using AJAX in asp:net and am trying to handle a situation where

  • 0

I am using AJAX in asp:net and am trying to handle a situation where an asp:button triggers both a javascript method and a codebehind c# method. To do this I am using onclick and onClientClick attributes for the button. I need a postback to occur for the codebehind to be called however this postback causes the javascript to not work because variables have lost state. Can anyone describe how to handle this? Possible with ajax and async postbacks? It’s starting to drive me a bit crazy!

Edit:
The javascript is actually for a google-map (v3), the c# code is for submitting to an sql db.

The map is initialized in the code-behind with:

protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack) {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "initialize_map();", true);
            submitButton.Command += new CommandEventHandler(this.submitButton_Click);
        }
    }

Here is some of the relevant code:

<asp:UpdatePanel runat="server" ID="Form" UpdateMode="Conditional">
<ContentTemplate>

(...form stuff...)

<asp:Button ID="submitButton" runat="server" Text="Submit" ValidationGroup="NewCallFormSubmit" OnClientClick="calcRoute(); return false;" onclick="submitButton_Click" />

</ContentTemplate>
</UpdatePanel>

<asp:UpdatePanel runat="server" ID="DisplayUpdatePanel" UpdateMode="Conditional">
<ContentTemplate>

 <h1>
  Pick-Up and Drop-Off Locations
  </h1>
     <!-- Map Layout -->
     <div id="map_canvas" style="width: 500px; height: 500px;"></div>                          

</ContentTemplate>
</asp:UpdatePanel>

…I think it would work if I could get the first updatepanel to postback on the button click, the second panel not to postback, and the button to still call the codebehind. So far no luck with this all happening at the same time.

  • 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-28T05:06:31+00:00Added an answer on May 28, 2026 at 5:06 am

    If you simply want to run your OnClientClick (client) code before your OnClick (server) code, try the following:

    ASP.NET

    <asp:Button ID="btn_mybutton" runat="server" Text="MyButton" OnClientClick="return JSFunction();" OnClick="CFunction"/>
    

    Javascript

    <script type="text/javascript">
        function JSFunction() {
            alert('Some JavaScript stuff');
            return true; 
        }
    </script>
    

    C#

    protected void CFunction(object sender, EventArgs e)
    {
        // Some server code
    }
    

    The JavaScript function is executed first and returned from before the server code is executed.

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

Sidebar

Related Questions

I'm trying to call an asp.net method using jquery/ajax from a button click on
I'm trying to make a login page using html, ajax & ASP.NET.The data is
I wish to execute a javascript function after asp.net postback with out using ajax.
I am using Asp.net MVC3 and trying to do a simple Ajax post to
I am trying to create a simple ajax chat using JQuery and ASP.NET. My
I am using ASP.net's AJAX framework and I am trying to do some exception
I am using an ajax htmleditor in asp.net web application so i am trying
How to render partial view in some specific div without using ajax in asp.net
I have an ASP.Net project using AJAX that I am putting on a server
I am using Asp.Net/C# ,In one of my pages I am using Ajax autocompleteextender

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.