Calling a server side button event handler via Jquery

Posted on 2010-11-24
Last Modified: 2012-05-10
Is it possible that we call a server side ASP.NET button event handler via Jquery on the client side.
In other words, I wnat to write a jquery function(called via OnClientClick) ,this function should call the server side event handler(onClick) of the same button.
This server side event handler is talking to database as well.

Urgently required!
I need to do this, because I cannot do the server side click because i have wrapped button with ( Update Panel and Content Template) in my model pop  in order to freeze the model dialog when the button is clicked, without doing it, the model pop was being continuously dsappeared at every click.

Question by:Ammar Iqbal
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Accepted Solution

ajb2222 earned 500 total points
ID: 34208162
the javascript you run in the onclientclick event needs to return a boolean value.  true if postback should occur, false if postback should be canceled.

<asp:Button id="btnTest" Text="Test" runat="server" OnClick="btnTest_Click" OnClientClick="return btnTestConfirm();" />

<script type="text/javascript">
    function btnTestConfirm() {
        var answer = confirm("Are you sure?")
        if (answer) {
            return true;  // this makes postback
        else {
            return false;  // this avoids postback

Open in new window


Author Comment

by:Ammar Iqbal
ID: 34208533
But I  want the server side event handler to be called indirectly via the jquery OnClientClick event handler

Expert Comment

ID: 34208700
ok this will call the postback from your java

setTimeout('__doPostBack(\'{button Control ID}\',\'\')', 0)

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

by:Ammar Iqbal
ID: 34208806
its  ASP.NET and C Sharp not java.
I do nort want to call the post back,Infact I just want to call a servier button event handler (on click event), form the "OnClientClick"  jquery script

Expert Comment

ID: 34208893
isn't jquery just a javascript library?  

ASP creates a javascript subroutine called "__doPostBack".  which does the postback for you.  You call this routine from your jquery script.    
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34216849
Just create a WebMethod and call via Page.WebMethod in javascript.

Author Closing Comment

by:Ammar Iqbal
ID: 34238112
partial solution

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question