[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1284
  • Last Modified:

Calling a server side button event handler via Jquery

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
Ammar Iqbal
Asked:
Ammar Iqbal
  • 3
  • 3
1 Solution
 
ajb2222Commented:
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
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
But I  want the server side event handler to be called indirectly via the jquery OnClientClick event handler
0
 
ajb2222Commented:
ok this will call the postback from your java

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

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
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
 
ajb2222Commented:
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
 
Alpesh PatelAssistant ConsultantCommented:
Just create a WebMethod and call via Page.WebMethod in javascript.
0
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
partial solution
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now