cagin
cagin

Reputation: 5920

How to trigger server side button's click event after javascript confirm dialog returns true

I have an input as count named in a repeater with hdncount hidden input. And I have a server side button out of repeater. This script runs onblur event of count. I want to trigger server side button's click event if client click OK button on confirmation. What should I do to do that?

<script type="text/javascript">

        function changeItemCount(input) {
            var hdnCount = $(input).closest("div").find("input[id=hdnCount]").val();
            var crrCount = $(input).closest("div").find("input[id=count]").val();

            if (hdnCount != crrCount) {
                var answer = confirm("Ürün adedi değiştirilecektir. Onaylıyor musunuz?");
                return answer;
            } else {
                return true;
            }
        }
    </script>

Upvotes: 0

Views: 11231

Answers (2)

Ricketts
Ricketts

Reputation: 5213

Use OnClientClick together with OnClick

<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" OnClientClick="return CheckGoJSEvents();" />

EDIT:

Didn't see that you had the function execute on the blur event. In that case you would not use the OnClientClick of the button. The answer posted by mattmanser would be correct.

If you wanted it to function from the button click, then you could use this method. Sorry for the confusion.

Upvotes: 0

mattmanser
mattmanser

Reputation: 5796

How to fire a button click event from JavaScript in ASP.NET

var answer = confirm("Ürün adedi değiştirilecektir. Onaylıyor musunuz?");

if(answer)
  __doPostBack('btnSubmit','OnClick'); //use the server-side ID of the control here

Upvotes: 2

Related Questions