cancel postback on onClientClicking

4 posts, 0 answers
  1. Jagat
    Jagat avatar
    135 posts
    Member since:
    Jan 2011

    Posted 25 Mar 2013 Link to this post

    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"   />
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 27 Mar 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jagat
    Jagat avatar
    135 posts
    Member since:
    Jan 2011

    Posted 28 Mar 2013 Link to this post

    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!!




  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 29 Mar 2013 Link to this post

    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.
Back to Top