HI All:
I have used a variation the Javascript code here to warn the user about moving to a new page if there is unsaved data on the current page. The "set_cancel(true)" statement stops the grid from moving to another page. However, the page number in the pager control advances to the new page (i.e., If I click the "next page" button but cancel the page, the grid stays on page one but the pager shows page 2). Is there any way to block this behaviour (or failing that is there any way I can set the page number back to the original)?
Thanks for your help.
John
I have used a variation the Javascript code here to warn the user about moving to a new page if there is unsaved data on the current page. The "set_cancel(true)" statement stops the grid from moving to another page. However, the page number in the pager control advances to the new page (i.e., If I click the "next page" button but cancel the page, the grid stays on page one but the pager shows page 2). Is there any way to block this behaviour (or failing that is there any way I can set the page number back to the original)?
Thanks for your help.
John
6 Answers, 1 is accepted
0
Hello,
Could you post the code you are using to achieve this behavior, or it will be better if you could upload runnable version of your project.. Thus all the people who want to help you will be able to do it in less time.
Regards,
Andrey
the Telerik team
Could you post the code you are using to achieve this behavior, or it will be better if you could upload runnable version of your project.. Thus all the people who want to help you will be able to do it in less time.
Regards,
Andrey
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

John
Top achievements
Rank 1
answered on 15 Mar 2012, 08:37 PM
Hi:
Thanks for your help. I'm afraid that the page in question is part of a very large project still under development so uploading a runnable version would be a problem. However, here is the grid's ClientSettings and the JavaScript that it runs when the user clicks the paging buttons:
Thank you for any help you can give me.
Thanks for your help. I'm afraid that the page in question is part of a very large project still under development so uploading a runnable version would be a problem. However, here is the grid's ClientSettings and the JavaScript that it runs when the user clicks the paging buttons:
CLIENTSETTINGS FOR GRID
<
ClientSettings
AllowColumnsReorder
=
"true"
ReorderColumnsOnClient
=
"true"
>
<
Resizing
AllowRowResize
=
"True"
EnableRealTimeResize
=
"True"
ResizeGridOnColumnResize
=
"True"
AllowColumnResize
=
"True"
ShowRowIndicatorColumn
=
"false"
/>
<
ClientEvents
OnCommand
=
"newPage"
/>
</
ClientSettings
>
JAVASCRIPT
// NEWPAGE: This function is tied to the grid's command client event. It pops up a warning if the
// user wishes to change the page without saving all the contents.
function newPage(sender, eventArgs)
{
var result = String.format("CommandName: {0}, CommandArgument: {1}", eventArgs.get_commandName(), eventArgs.get_commandArgument());
// If this is a page event, process
if (eventArgs.get_commandName() == "Page") {
// If the page is dirty, ask the client if want to continue
if (document.getElementById('<%=hfPageDirty.ClientID %>').value == "Y") {
// Ask the user whether or not to continue
if (confirm("There is unconfirmed data that will be lost when you go to the new page. Do you wish to continue?")) {
// Do not cancel the page change
eventArgs.set_cancel(false);
document.getElementById('<%=hfPageDirty.ClientID %>').value = "N";
} else {
// Cancel the page change
eventArgs.set_cancel(true);
}
}
}
}
Thank you for any help you can give me.
0
Hello,
I made a sample project to test your case, but it is working on my end as expected. Give the project a try and check what are the differences with your project.
Greetings,
Andrey
the Telerik team
I made a sample project to test your case, but it is working on my end as expected. Give the project a try and check what are the differences with your project.
Greetings,
Andrey
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

John
Top achievements
Rank 1
answered on 16 Mar 2012, 05:14 PM
Hello Andrey:
Thanks for your help. However, your code doesn't seem to do what I hoped it would do. The goal is, under a set of conditions, if the user clicks any of the page buttons (e.g., next page, previous page, first page, etc) in the grid, the grid will not advance to the next page and the page number in the grid pager will not advance. I can accomplish the former but not the latter.
To return to your simulation demo code, the way that I would imagine it to work in is that if I hit any of the pager buttons (as mentioned above), the page won't advance. For example, if I am on page one of the grid and I click the "next page" button, the grid stays on page one and the pager number shows page one. This would simulate the situation where the "stop paging" conditions were true.
By the by, I think that you have an error in your JavaScript. The function header accepts an event variable called "event." However, the script itself tries to access this by the variable name "eventArgs." I corrected this in your demo, but as I mentioned above, the paging was not stopped.
John
Thanks for your help. However, your code doesn't seem to do what I hoped it would do. The goal is, under a set of conditions, if the user clicks any of the page buttons (e.g., next page, previous page, first page, etc) in the grid, the grid will not advance to the next page and the page number in the grid pager will not advance. I can accomplish the former but not the latter.
To return to your simulation demo code, the way that I would imagine it to work in is that if I hit any of the pager buttons (as mentioned above), the page won't advance. For example, if I am on page one of the grid and I click the "next page" button, the grid stays on page one and the pager number shows page one. This would simulate the situation where the "stop paging" conditions were true.
By the by, I think that you have an error in your JavaScript. The function header accepts an event variable called "event." However, the script itself tries to access this by the variable name "eventArgs." I corrected this in your demo, but as I mentioned above, the paging was not stopped.
function Command(sender, args) {
debugger;
if (eventArgs.get_commandName() == "Page") {
}
else {
eventArgs.set_cancel(true);
}
}
John
0
Hi,
I think I have misunderstood your requirement in the previous posts.
In order to achieve your goal you need to find the pager buttons and change their onclick handler to nothing. Before that you could the store the old handler so you are able to revert to it at some point. You could use something to the following code:
Kind regards,
Andrey
the Telerik team
I think I have misunderstood your requirement in the previous posts.
In order to achieve your goal you need to find the pager buttons and change their onclick handler to nothing. Before that you could the store the old handler so you are able to revert to it at some point. You could use something to the following code:
var
oldClickFunction = a.onclick;
a.onclick = myCustomFunction(){
if
(some condition is met)
{
oldClickFunction();
}
}
Kind regards,
Andrey
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

John
Top achievements
Rank 1
answered on 21 Mar 2012, 02:01 PM
Hi Andrey:
Thanks for that code. I'll give it a try.
John
Thanks for that code. I'll give it a try.
John