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

Fire javascript alert before changing page

2 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TANSERI
Top achievements
Rank 1
TANSERI asked on 09 Sep 2013, 01:28 PM
Hi all,

I would like to fire a javascript confirm popup when the user wants to change page (by setting a page number or by using previous / next page buttons).

Here is a quick description of the grid :

A user can update some input fields in a grid and a button below the grid lets the user save the values. I would like to prevent him from losing its updated data when he changes page by displaying a javascript confirm popup.

The confirm popup will ask if he really wants to change page and if it is the case, we lauch the postback and we change page. If not, the page change event is canceled and the user can save its values.


Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Sep 2013, 06:14 AM
Hi Tanseri,

Please try the following code snippet to show confirmation on paging.

ASPX:
<ClientSettings>
 <ClientEvents OnGridCreated="gridCreated" />
</ClientSettings>

JS:
<script type="text/javascript">
  
    function gridCreated(sender, args) {
        var pagerRow = sender.get_masterTableView().get_element().tFoot;
        var anchors = pagerRow.getElementsByTagName('a');
        for (var i = 0; i < anchors.length; i++) {
            if (anchors[i].className != "rgCurrentPage" && anchors[i].href.indexOf("javascript:__doPostBack") > -1) {
                var clickScript = anchors[i].attributes["onclick"].value;
                anchors[i].onclick = confirmPage;
            }
        }
 
        var submits = pagerRow.getElementsByTagName('input');
        for (var i = 0; i < submits.length; i++) {
            if (submits[i].type == "submit") {
                submits[i].onclick = confirmPage;
            }
        }
    }
 
    function confirmPage() {
        return confirm("Are you sure you want to page?");
    }
</script>

Thanks,
Shinu
0
TANSERI
Top achievements
Rank 1
answered on 11 Sep 2013, 11:42 AM
Hi Shinu,

Thanks for replying, actually it worked only for the numeric pager but for the previous / next buttons it did not work so I used the following post to handle the confirm popup.

http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-paging---pageindexchanged-event-issue.aspx

Thanks again.
Tags
Grid
Asked by
TANSERI
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
TANSERI
Top achievements
Rank 1
Share this question
or