How to prevent AutoPostBack when DropDownlist is selected using jQuery

后端 未结 4 1162
面向向阳花
面向向阳花 2021-01-22 19:32

I want to show a confirm dialog when the user selects an item in a DropDownList. If the user presses \"Cancel\", I want to stop the postback. Here is the function I add to the o

4条回答
  •  春和景丽
    2021-01-22 19:58

    You need to return from that function as well, like this:

    $('.warn').change(imitateConfirmUnload);
    

    Currently the return value isn't being used. This would also work:

    $('.warn').change(function() {
      return imitateConfirmUnload();
    });
    

    Also, I'm pretty sure you want an equals check here:

    if (window.onbeforeunload == null)
        return true;
    

    Currently it's nulling out the onbeforeunload handler if it was present.

提交回复
热议问题