hi all,
i have a custom validator for a RadUpload control in the grid. i want the validator to validate empty text only on insert not on update, on update it's not required to upload a file but if the user selected one it should get validated.
i have put this code in ItemDataBound
but it didn't work bcoz the ClientValidationFunction still validating empty text in both cases. So i tried to modify this function to check if the item is in edit or insert mode using get_isItemInserted, but sth is wrong and i coudn't fix it. Here is my code
And here is my column if nedded
Any ideas plzzz..??
thnx in advance
i have a custom validator for a RadUpload control in the grid. i want the validator to validate empty text only on insert not on update, on update it's not required to upload a file but if the user selected one it should get validated.
i have put this code in ItemDataBound
| Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
| If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then |
| Dim item As GridEditableItem = CType(e.Item, GridEditableItem) |
| Dim imageValidator As CustomValidator = CType(item.FindControl("CustomValidator2"), CustomValidator) |
| If (item.OwnerTableView.IsItemInserted) Then |
| imageValidator.ValidateEmptyText = True |
| Else |
| imageValidator.ValidateEmptyText = False |
| End If |
| End If |
| End Sub |
but it didn't work bcoz the ClientValidationFunction still validating empty text in both cases. So i tried to modify this function to check if the item is in edit or insert mode using get_isItemInserted, but sth is wrong and i coudn't fix it. Here is my code
| function validateImageType(source, e) |
| { |
| e.IsValid=false; |
| var upload=$find(source.parentNode.getElementsByTagName('div')[0].id); |
| var inputs=upload.getFileInputs(); |
| if (e.get_isItemInserted==true) |
| { |
| for (var i = 0; i < inputs.length; i++) |
| { |
| //check for empty string or invalid extension |
| if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) |
| { |
| e.IsValid=true; |
| break; |
| } |
| } |
| } |
| else |
| { |
| if (inputs.length>0) |
| { |
| for (var i = 0; i < inputs.length; i++) |
| { |
| //check for invalid extension only |
| if (upload.isExtensionValid(inputs[i].value)) |
| { |
| e.IsValid=true; |
| break; |
| } |
| } |
| } |
| else |
| { |
| e.IsValid=true; |
| } |
| } |
| } |
And here is my column if nedded
| <telerik:GridTemplateColumn HeaderText="Image" SortExpression="image" UniqueName="image" AutoPostBackOnFilter="true" DataField="image"> |
| <ItemTemplate> |
| <img src='/Files/PhotoGallery/<%# Eval("image") %>' width="100" height="100" /> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadUpload ID="RadUpload1" runat="server" AllowedFileExtensions=".jpg,.jpeg" ControlObjectsVisibility="None"></telerik:RadUpload> |
| <asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="Allowed file extensions are .jpg, .jpeg" ClientValidationFunction="validateImageType" Display="Dynamic"></asp:CustomValidator> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
Any ideas plzzz..??
thnx in advance
