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

Fire validation for template controls when paging

2 Answers 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 12 Oct 2012, 09:02 PM
I have a RadDatePicker attached to a RequiredFieldValidator as part of a Template column.

I want the validation to fire whenever the grid attempts to page.  Looks like, by default, this does not occur.  Even if the RadDatePicker is empty, the validation does not fire when I page the grid.

Is there anyway I can force this?

I attempted to respond to the OnCommand client event when it is of type "Page", force the validation.  

function grid_OnCommand(sender, eventArgs) {
                var c = eventArgs.get_commandName();
                if (c == "Page") {
                    if (!Page_ClientValidate()) {
                        eventArgs.set_cancel(true);
                    }
                }
            }

While the validation does fire and the grid's data does not refresh, the pager still moves to the next page.  The set_cancel does not seem to take effect fully when paging.

Any help would be greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Oct 2012, 04:39 PM
Hi Robert,

You could try the following approach:
<ClientEvents OnCommand="gridCommand" />
  JavaScript:
Telerik.Web.UI.GridTableView.prototype.page = (
             function (command) {
                 if (!original_page)
                     var original_page = this.page;
                 if (Page_ClientValidate())
                     return function () { original_page(command); }
             });
function gridCommand(sender, args) {
}

That should do the trick. Please give it a try and let me know about the result.

All the best,
Eyup
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
Robert
Top achievements
Rank 1
answered on 18 Oct 2012, 01:46 AM
This worked great.  Thanks for the assistance.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Robert
Top achievements
Rank 1
Share this question
or