javascriptasp.nettelerikdopostbacktelerik-scheduler

Strange behavior of confirmation in Telrik ?


somePage.aspx

<asp:LinkButton Runat="server" ID="butDelete" CommandName="Delete" OnClientClick="Confirmation();return flag;"><img src="images/delete.gif" border="0" title='<asp:Literal runat="server" Text="<%$ Resources:ClarityResources, resDelete %>" />'></asp:LinkButton>

ClientSideCode.js

 function confirmCallBackFn(sender) {
             debugger;
             if (sender)
                 flag = true;
             else
                 flag = false;
             return flag;
         }
         function Confirmation(sender,args) {
             debugger;
             radconfirm('Are you sure you want to delete this file?',  confirmCallBackFn);
         }

but the on click always returns false which is default value set for the flag variable When i did debugging i seen that the on client click the method confirmation gets called and it returns the default value false to the control and after clicking on the confirmation box's Yes or cancel it again runs the call back method confirmCallBackFn(sender) seperatly which returns flag but not in same thread but in different thread. I tried different ways to solve it but i am stuck . so any help would be great .


Solution

  • You're trying to treat the radconfirm in the same way as a plain javascript confirm(), this isn't done in a like-for-like manner. I'll start with the Confirmation function.

    function Confirmation(sender, args) {
        debugger;
        // The line below will open a rad confirmation window, it will not wait for the response
        radconfirm('Are you sure you want to delete this file?', confirmCallBackFn);
    }
    

    To ensure that it doesn't automatically post back the above function should be changed as follows:

    function Confirmation(sender, args) {
        debugger;
        // This line will open a rad confirmation window, it will not wait for the response
        radconfirm('Are you sure you want to delete this file?', confirmCallBackFn);
        // The line below will prevent the control from automatically posting back
        return false;
    }
    

    The next step is correcting the call back function; The parameter passed into the function, as can be seen from the code rather than the parameter name is the boolean representation of the result from the confirmation box.

    function confirmCallBackFn(sender) {
        debugger;
        if (sender)
            flag = true;
        else
            flag = false;
        return flag;
    }
    

    The previously written function returns a value, but this isn't used anywhere. The following code will perform the required action

    function confirmCallBackFn(arg) {
        debugger;
        if (arg) {
            // The line below will perform a post back, you might want to trigger this a different way
            __doPostBack(sender.id, "");
        }
    }
    

    Unfortunately as the sender is not passed into the callback function it is necessary to declare the function within the other JavaScript function as follows:

    function Confirmation(sender) {
        debugger;
        // The callback function
        function confirmCallBackFn(arg) {
            debugger;
            if (arg) {
                // Triggers postback only when confirmation box returns true
                __doPostBack(sender.id, "");
            }
        }
        // This line will open a rad confirmation window, it will not wait for the response
        radconfirm('Are you sure you want to delete this file?', confirmCallBackFn);
        return false;
    }
    

    You might find the following link useful in regards to using the radconfirm in the same way as a confirm:

    http://demos.telerik.com/aspnet-ajax/window/examples/confirmserverclicks/defaultcs.aspx.