jquery button trigger server side onclick event

16,856

https://stackoverflow.com/a/10583339/1202242

I used two button, and one is hidden. It solved my problem perfectly

Share:
16,856
pita
Author by

pita

Updated on June 04, 2022

Comments

  • pita
    pita almost 2 years

    I am using a jquery dialog, when user click ok, the server side onclick event should be fired, if click cancel, nothing happened.

    i have to prevent the click function at the beginning by preventDefault() function.

      $(document).ready(function () {
             $("#<%=submit.ClientID %>").click(function (event) {
                 event.preventDefault();
                    $("#confirm").dialog({
                        buttons: {
                            "OK": function () {  $(this).dialog("close"); 
                                  Here should be the code to trigger the server side click event
    
    
                         },
                            "Cancel": function () { $(this).dialog("close");},
                        } 
                    });
             });
         });
    

    I don't know how to trigger a server side onclick event. any ideas? thanks

  • pita
    pita almost 12 years
    if I move the event.preventDefault() into the "cancel" function, the server side code will run when click the "submit" button before user click the "ok" on the popuped dialog
  • Sagiv Ofek
    Sagiv Ofek almost 12 years
    so if you don't want to create a submit you need to put it at the beginning (like you did) and call $("#your_form_id").submit() manually on "OK" function or create an ajax call instead.
  • pita
    pita almost 12 years
    that is my problem, I tried to use $("#your_form_id").submit() which didn't fire submit_onClick() function on the server side, and i don't know how to use an ajax, could you give me some example?
  • Sagiv Ofek
    Sagiv Ofek almost 12 years
    i updated my comment. your dialog function should return a value. pass this value to the function called on submit event.
  • Adriano Repetti
    Adriano Repetti almost 12 years
    @Pita I remember some issues (with some some browsers) related to buttons with ID "submit". I'm not sure so any information will be welcome. Anyway this should be work (I use it too) but you may have to rename your button to something else.