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

Required field validation for GridEditorColumn

3 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 26 Nov 2012, 07:28 PM
Hi guys

I am staring at this but cannot see anything wrong. But it does not trigger validation when there is no text entered in the editor on Update. What am I missing?

Thanks

Clive
PS Q2 2010 asp.net 4 .   I am not using ajax manager on this page

<telerik:GridHTMLEditorColumn DataField="BodyText" HeaderText="BodyText" SortExpression="BodyText" UniqueName="BodyText" ColumnEditorID="MyColumnEditor1">
 </telerik:GridHTMLEditorColumn>
 
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
        If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
            Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim editor As GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("BodyText"), GridTextBoxColumnEditor)
            Dim cell As TableCell = CType(editor.TextBoxControl.Parent, TableCell)
            Dim validator As RequiredFieldValidator = New RequiredFieldValidator
            editor.TextBoxControl.ID = "MyColumnEditor1"
            validator.ControlToValidate = editor.TextBoxControl.ID
            validator.ErrorMessage = "Please enter some text!"
            cell.Controls.Add(validator)
        End If
    End Sub

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Nov 2012, 04:45 AM
Hi,

Please try the following code snippet to give validation for GridHTMLEditorColumn.

VB:
Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
        Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim editor As GridHTMLEditorColumnEditor = DirectCast(item.EditManager.GetColumnEditor("BodyText"), GridHTMLEditorColumnEditor)
        Dim cell As TableCell = DirectCast(editor.Editor.Parent, TableCell)
        Dim validator As New RequiredFieldValidator()
        editor.Editor.ID = "MyColumnEditor1"
        validator.ControlToValidate = editor.Editor.ID
        validator.ErrorMessage = "Please enter some text!"
        cell.Controls.Add(validator)
    End If
End Sub

Thanks,
Shinu.
0
Clive Hoggar
Top achievements
Rank 1
answered on 27 Nov 2012, 10:41 AM
Hi

Thanks for quick reply

I did try this code, and there were no design time or run time errors, but it did not trigger the validation for the GridEditor Column.
In the same grid there are declarative validators for a text box and a combo box, which do fire as expected, so all seems to be OK ajax-wise.

I guess could revert to a template column and a radcombobox, but it seemed more elegant to use the special column provided.
Has anyone got the validation working for this column type?

Thanks

Clive

0
Angel Petrov
Telerik team
answered on 29 Nov 2012, 03:11 PM
Hi Clive,

The purpose of the GridHTMLEditorColumn is to display HTML and not to validate controls. When editing the content of this column you are editing the HTML in the field. If you want to put controls in a column I suggest that you use GridTemplateColumn instead. By doing so you would be able to validate the controls inside.

Regards,
Angel Petrov
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.
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Clive Hoggar
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or