Messi jQuery Confirmation Box Redirect

Viewed 99

I have a jQuery script in WebForms that I'm trying to get to display a message on a button click event. I have the script in my .aspx file and I'm calling it in code-behind. The issue is how do I redirect if a user clicks the confirm and not the cancel button?

.ASPX Script:

<script type="text/javascript">

        $(window).unload(function () {
            CloseWindow();
        })
        //var newEmployeeDetail = document.getElementById(hfNe)

        function confirmAppointEmployee() {
            debugger;
            Messi.ask("Employee appointed successfully",
                function (val) {
                    if (val == false) {
                    $("[id*=Cancel]").click();
                }
                else {
                        $("[id*=Confirm]").click();
                }

            }, {
                buttons: [{ id: '0', label: 'Confirm', val: true, 'class': 'btn-primary' }, { id: '0', label: 'Cancel', val: false }]
            });
        }

    </script>

Code Behind:

 ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script>confirmQuickAppointEmployee()</script>"); 

The below code is the string that needs to be called to redirect the user.

private string PersonalInformationDetailUrl = Company.Framework.SmartNavigationPersonnel.SmartNavigation.GetUrlByPageName(Company.Framework.SmartNavigationPersonnel.SmartNavigation.PageNameList.PersonalInformationDetail) + "?AllowAddOption=true&AllowDeleteOption=true&RefreshMenuPage=true";

I have tried the below method but both the cancel and confirm button do the same thing.

  var confirm = "$(document).ready(function(){ new Messi('Employee appointed successfully', " +
                        "{title: 'Title', buttons: [{id: 0, label: 'Close', val: 'false'},{id: 0, label: 'Confirm', val: 'true'}], " +
                        "callback: function(val) { window.location.href = '" + Functions.FixClientUrl(PersonalInformationDetailUrl) + "' }}); });";
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", confirm, true);
1 Answers

It all boils down to your confirmQuickAppointEmployee Javascript function, that is not specified in the question. It's clear that it must be a confirmation dialog/window where you have a confirm and a cancel button/feature. However, since the implementation is not shared in the question, I can only offer general guidelines:

Find out what that function is

Open your brower's Dev Tools, go to its Console tab and type:

confirmQuickAppointEmployee + ""

and then hit Enter. This will show you the source-code of this function if it exists. Naturally, you should be at your website in order to perform this test. Seeing the source-code of this function might provide you some information that might help finding out what the answer is.

Find usage examples

In your project source-code search for all occurrences of confirmQuickAppointEmployee to see how it was used so far. If you look at all usages, sequantially and carefully, then you might find some examples where confirm/cancel differ. If you find such an example, then you will just need to understand how confirm/cancel click was identified and apply the same idea at your problem.

A possibility

Javascript has a native confirm dialog which can be used as a function call and returns a boolean. Try this in your Console:

if (confirm("")) {
    alert("confirmed");
} else {
    alert("cancelled");
}

if your confirmQuickAppointEmployee happens to mimic this behavior, then you are able to use it similarly. Of course, this largely depends on confirmQuickAppointEmployee, which is not shared in the question.

Related