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

Display issue with validator error message

3 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynda Golomb
Top achievements
Rank 1
Lynda Golomb asked on 23 Dec 2009, 04:12 PM
Hi,
I followed the example of adding a validation control to a grid in edit mode.
I have a grid with EditMode="InPlace", and after the validation control is added the error message distorts the display of the textbox.
How can I control this (for instance, add a line break between the edit text box and the error message that willbe displayed, i.e the validator control)?
I would like the error message to be displayed underneath the editable textboxes in edit mode.
Thanks,
Lynda

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Dec 2009, 07:41 AM
Hi,

You can add a  LiteralControl to the control collection before you add your validator control. This will help insert a line break in between the TextBox and the validator control:

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem item = e.Item as GridEditableItem; 
                GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("CompanyName"); 
                TableCell cell = (TableCell)editor.TextBoxControl.Parent; 
                RequiredFieldValidator validator = new RequiredFieldValidator(); 
                editor.TextBoxControl.ID = "ID_for_validation"
                validator.ControlToValidate = editor.TextBoxControl.ID; 
                validator.ErrorMessage = "*"
                cell.Controls.Add(new LiteralControl("<br/>")); 
                cell.Controls.Add(validator); 
            } 
        } 


Thanks,
Princy
0
Ashwin Kumar
Top achievements
Rank 1
answered on 04 Feb 2010, 09:00 AM
along the same lines, how do I display an error message within an edit form, or custom edit form template.  I would need to display this in a hierarchical grid, each error message appearing at the appropriate edit form, at the appropriate level of hierarchy.
0
Iana Tsolova
Telerik team
answered on 09 Feb 2010, 01:50 PM
Hello Ashwin,

Should the mentioned error message come with associated validator, or you just want to display it in a Label or other control?
In both case, you will need to add the corresponding control to each edit form. Form more information on how to distinguish edit forms in hierarchy, please refer to the below topic:

http://www.telerik.com/help/aspnet-ajax/grddistinguishgridrowsinhierarchyonitemdatabound.html

Kind regards,
Iana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Lynda Golomb
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ashwin Kumar
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or