Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling a server side button event handler via Jquery

Posted on 2010-11-24
7
Medium Priority
?
1,282 Views
Last Modified: 2012-05-10
Hi,
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 asp.net 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 asp.net button with (asp.net 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.

0
Comment
Question by:Ammar Iqbal
[X]
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
7 Comments
 
LVL 6

Accepted Solution

by:
ajb2222 earned 1000 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
        }
    }
</script>

Open in new window

0
 
LVL 1

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
0
 
LVL 6

Expert Comment

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

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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

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
0
 
LVL 6

Expert Comment

by:ajb2222
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.    
0
 
LVL 21

Expert Comment

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

Author Closing Comment

by:Ammar Iqbal
ID: 34238112
partial solution
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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