Hello,
Does anyone know which event on the RadGrid I can dynamically add RequiredFieldValidators and have them fire client side? Physically placing the Validators inside of the <EditTemplate> works like a champ.
Right now we are using the ItemDataBound, and also have tried the ItemCreated event. Those seem to be the only places to inject validators when the update button is clicked...
The .AddValidator method is an extension method tied to controls to determine which validation message to assign to the validator and then dynamically add the validator. This code works on the rest of the site, just not for InPlace editing of grids so far.
Code to add the validator to the page. Maybe I'm adding the validator to the wrong place, but I'd think that control.Parent would represent the "cell" the control lives in.
Sample ItemDataBound method
And the GridHelper function does this:
Does anyone know which event on the RadGrid I can dynamically add RequiredFieldValidators and have them fire client side? Physically placing the Validators inside of the <EditTemplate> works like a champ.
Right now we are using the ItemDataBound, and also have tried the ItemCreated event. Those seem to be the only places to inject validators when the update button is clicked...
The .AddValidator method is an extension method tied to controls to determine which validation message to assign to the validator and then dynamically add the validator. This code works on the rest of the site, just not for InPlace editing of grids so far.
Code to add the validator to the page. Maybe I'm adding the validator to the wrong place, but I'd think that control.Parent would represent the "cell" the control lives in.
// control is the Control validation is being added tocontrol.Parent.Controls.Add(requiredFieldValidator);Sample ItemDataBound method
protected void rgPmpDetails_ItemDataBound(object sender, GridItemEventArgs e){ const string valGroup = "vgEditPmpDetails"; GridHelper.AddEditValidator(e, "rntbCreditPercentGrid", valGroup, "Premium Credit"); GridHelper.SetFocusToFirstControlWhenInEditMode(e, "rntbCreditPercentGrid");}And the GridHelper function does this:
public static void AddEditValidator(GridItemEventArgs e, string controlId, string validationGroup, string fieldName, bool isMultiSelect = false){ if ((e.Item is GridEditableItem) && e.Item.IsInEditMode) { Control control = e.Item.FindControl(controlId); if (control != null) { if (control is TextBox) { (control as TextBox).ValidationGroup = validationGroup; (control as TextBox).AddValidator(fieldName); } else if (control is DropDownList) { (control as DropDownList).ValidationGroup = validationGroup; (control as DropDownList).AddValidator(fieldName); } else if (control is RadNumericTextBox) { (control as RadNumericTextBox).ValidationGroup = validationGroup; (control as RadNumericTextBox).AddValidator(fieldName); } else if (control is RadComboBox) { (control as RadComboBox).ValidationGroup = validationGroup; (control as RadComboBox).AddValidator(fieldName, isMultiSelect); } else if (control is RadDatePicker) { (control as RadDatePicker).DateInput.ValidationGroup = validationGroup; (control as RadDatePicker).AddValidator(fieldName); } else { throw new NotImplementedException("Controls of type [" + control.GetType() + "] have not been implemented in GridHelper.AddEditValidator."); } } ImageButton imageButton = e.Item.FindControl("UpdateButton") as ImageButton; if (imageButton != null) { imageButton.ValidationGroup = validationGroup; } }}