This is a migrated thread and some comments may be shown as answers.

cancel postback on onClientClicking

3 Answers 1142 Views
Button
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 25 Mar 2013, 08:59 PM
I'm checking if the internet is available or not by pinging my server. This method is called in onClientClicking event of the button.

If not connected to the internet I want to prevent the postback.
It displays 'Not connected to internet' message but after the user clicks 'OK' , it does a postback.

function checkinternetOnButtonClick(button, args) {
                $.ajax({
                    url: 'http://www.MyDomainName.com',
                    success: function() {
                           
 
                    },
                    error: function() {
                    alert('No internet connection available on button click!');
                    args.set_cancel(true);
                        return false;
                    }
                });
            }
<telerik:RadButton ID="btnBulkUpdate" runat="server" Text="Bulk Update" Width="150px"
                               Font-Size="Medium" OnClientClicking = "checkinternetOnButtonClick"   />

3 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 27 Mar 2013, 01:45 PM
Hello Jagat,

The OnClientClicking event executes too quickly, so that the set_cancel method in the error handler of the ajax request could not be executed.

What I can suggest you in that case is to simply cancel the postback of the RadButton at the beginning of the checkinternetOnButtonClick JavaScript function. Then you can trigger a button click on the success handler of the ajax request in order to make the postback. For example:

<script type="text/javascript">
    function checkinternetOnButtonClick(button, args) {
        args.set_cancel(true);
        $telerik.$.ajax({
            url: 'http://www.MyDomainName.com',
            success: function () {
                button.click();
            },
            error: function () {
                alert('No internet connection available on button click!');
            }
        });
    }
</script>
You can also find a similar scenario with the RadConfirm button located in Button - Confirm Postback online demo.

Kind regards,
Danail Vasilev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jagat
Top achievements
Rank 1
answered on 28 Mar 2013, 10:57 PM
Thanks Danail,

I'm yet to try your suggestion.

I also need to check for internet connection when pageNumber on the RadGrid's pager  is clicked. How to I call checkinternetOnButtonClick function?

Thanks for your help!!




0
Danail Vasilev
Telerik team
answered on 29 Mar 2013, 05:28 PM
Hi Jagat,

You can use the client-side event handlers OnPageIndexChanging or OnPageSizeChanging of the DataPager object, and there you can call the desired JavaScript function.

Greetings,
Danail Vasilev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Button
Asked by
Jagat
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Jagat
Top achievements
Rank 1
Share this question
or