I'm using a radgrid with a templated edit form and popup edit mode. Most of my validators are requireduiredfieldvalidators but one of my fields need to be validated agains the database. I therefore need to use a CustomValidator which is OK but if I do the validation server side then the error is not shown at the same time as the client side validator errors in the validationsummary.
Therefore I'm trying to call an AJAX method in the custom validator:
This calls the a server side method:
public void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
In this method I would like to perform the validation and then set the IsValid flag on the customervalidator. The problem I am having is finding the CustomValidator control in the AjaxRequest method on the server. The SelectedItems property on the RadGrid is empy and RadGrid.FindControl("Customvalidator1") returns null. Is this possible? Or is there an easier way to do this?
10 Answers, 1 is accepted
Unfortunately RadGrid1.EditItems is empty.
If you have at least one item in edit mode then the EditItems collection should not be empty.
Please, take a look at the attached sample for comparison with your implementation and let us know of the result.
the Telerik team
You need to obtain a reference to the insert item and then use the FindControl method to get hold of the validator:
All the best,
the Telerik team
I have the same problem.
I try to validate an insert form.
When I check (was my first thought) Grid1.EditItems - I get nothing.
This brought me to this thread.
Than I tried the approach here Grid1.MasterTableView.GetInsertItem()
"Insert item is available only when grid is in insert mode"
Ok - my next idea - the master is not in insert - it is one of the childs
So I tried this Grid1.MasterTableView.DetailTables.GetInsertItem - the same result!!!
And yes index 1 is correct - I have to detail tables.
By the way - it is a bad thing that GridTableView can't have an ID.
So in this case I user .. DetailTables - and get it running somehow.
Later the customer asks to put this detail table in the first position -- and the I have to "renumber" all the code behind.
But that's a different thing - my current problem - how can I access the controls in the insert form from a validator handler?
The GetInsertItem() method of the GridTableView can be used to get reference to the GridDataInsertItem when the insertion form is displayed.
To access the GridDataInsertItem container from within event handler of a validator inside it, use the NamingContainer property of the validator object from in its server handler.
Here is how this can be done for the edited items in the grid (see the SelectedIndexChanged handler in the code):
the Telerik team
thanks a lot - this did the trick :)
ULTRAFAST support - really cool - you made my day!!!
Here is the snippet made out of your tip:
Uh...where's the reference to SelectedIndexChanged on the page you referenced:
"Here is how this can be done for the edited items in the grid (see the SelectedIndexChanged handler in the code):
Can't find this as part of the examples appearing on the page you referenced...Because, I'd really like to find out how to reference a set of inserted items based upon the first inserted item's (a radcombobox) SelectedIndexChanged event...
I would suggests you to use the approach below for achieving the required functionality:
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.