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

Control Validation

1 Answer 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle Jones
Top achievements
Rank 1
Kyle Jones asked on 18 Aug 2009, 04:01 PM
Hey,

I am having problems with my control validation.  I am using the validation that you provided on this page: Validation.  My problem is that when my application calls my insert or update I am not able to grab the values inside my grid that have the validators attached to them.  When I remove the validation my code grabs the vaules properly.  Any help would be great.

Here is the code that is grabbing data out of my grid:

GridEditableItem editedItem = e.Item as GridEditableItem;
            GridEditManager editManager = editedItem.EditManager;

            int i = 0;
            foreach (Telerik.Web.UI.GridColumn column in e.Item.OwnerTableView.RenderColumns)
            {
                if (column is IGridEditableColumn)
                {
                    IGridEditableColumn editableCol = (column as IGridEditableColumn);
                    if (editableCol.IsEditable)
                    {
                        IGridColumnEditor editor = editManager.GetColumnEditor(editableCol);

                        if (editor is GridDropDownColumnEditor)
                        {
                            CoverageUpdates[i] = (editor as GridDropDownColumnEditor).SelectedValue;
                            i++;
                        }
                        else if(editor is GridNumericColumnEditor)
                        {
                            CoverageUpdates[i] = (editor as GridNumericColumnEditor).Text;
                            i++;
                        }
                        else
                        {
                            CoverageUpdates[i] = (editor as GridTextColumnEditor).Text;
                            i++;
                        }
                    }
                }
            }

Here is my validator code:

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;

                GridNumericColumnEditor editor = (GridNumericColumnEditor)item.EditManager.GetColumnEditor("CoverageLimit");

                TableCell cell = (TableCell)editor.NumericTextBox.Parent;

                RequiredFieldValidator validator = new RequiredFieldValidator();
                editor.NumericTextBox.ID = "clID";
                validator.ControlToValidate = editor.NumericTextBox.ID;
                validator.ErrorMessage = "Required";
                cell.Controls.Add(validator);

                GridNumericColumnEditor editor2 = (GridNumericColumnEditor)item.EditManager.GetColumnEditor("Deductible");

                TableCell cell2 = (TableCell)editor2.NumericTextBox.Parent;

                RequiredFieldValidator validator2 = new RequiredFieldValidator();
                editor2.NumericTextBox.ID = "dId";
                validator2.ControlToValidate = editor2.NumericTextBox.ID;
                validator2.ErrorMessage = "Required";
                cell2.Controls.Add(validator2);
            }






Thanks,

Kyle Jones

1 Answer, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 21 Aug 2009, 08:13 AM
Hello Kyle,

Could you please try removing the lines of your code where you set the NumericTextBox ID and see if it
works thus:

...  
RequiredFieldValidator validator = new RequiredFieldValidator();  
validator.ControlToValidate = editor.NumericTextBox.ID;  
validator.ErrorMessage = "Required";  
cell.Controls.Add(validator);  
 
GridNumericColumnEditor editor2 = (GridNumericColumnEditor)item.EditManager.GetColumnEditor("Deductible");  
 
TableCell cell2 = (TableCell)editor2.NumericTextBox.Parent;  
 
RequiredFieldValidator validator2 = new RequiredFieldValidator();  
validator2.ControlToValidate = editor2.NumericTextBox.ID;  
validator2.ErrorMessage = "Required";  
cell2.Controls.Add(validator2);  
.... 

Let me know how it goes.

Kind regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Kyle Jones
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or