Required Field Validator for Upload in grid

Thread is closed for posting
4 posts, 0 answers
  1. Jim
    Jim avatar
    42 posts
    Member since:
    Mar 2009

    Posted 11 Feb 2010 Link to this post

    The telerik grid example:
    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/raduploadinajaxifiedgrid/defaultcs.aspx?product=upload

    has the following:

            protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
            {  
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
                {  
                    GridBinaryImageColumnEditor editor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("Upload") as GridBinaryImageColumnEditor;  
                    TableCell cell = (TableCell)editor.RadUploadControl.Parent;  
                    CustomValidator validator = new CustomValidator();  
                    validator.ErrorMessage = "Please select file to be uploaded";  
                    validator.ClientValidationFunction = "validateRadUpload";  
                    validator.Display = ValidatorDisplay.Dynamic;  
                    cell.Controls.Add(validator);  
                }  
            }  
     
    but it is using a specific column type.
    how do I add a required field validator to the upload if I am doing this:
                                            <telerik:gridtemplatecolumn uniquename="Upload" HeaderText="File Name">  
                                                <itemtemplate> 
                                                    <asp:HyperLink ID="hlFile" runat="server" Target="_blank" /> 
                                                </itemtemplate> 
                                                <edititemtemplate> 
                                                    <telerik:radupload id="RadUpload1" runat="server" ControlObjectsVisibility="None" InitialFileInputsCount="1" /> 
                                                </edititemtemplate> 
                                            </telerik:gridtemplatecolumn> 
     

    I noticed this example:
    http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx
    what about validation on the attachment column?
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 12 Feb 2010 Link to this post

    Just add the CustomValidator control to the EditItemTemplate.
  3. Jim
    Jim avatar
    42 posts
    Member since:
    Mar 2009

    Posted 12 Feb 2010 Link to this post

    I don't think that will work. I tried adding a required validator to the edit item template, and it throws an error. The solution is not that simple unless you use a generic ASP.Net file upload. Probably because of the telerik controls ability to upload multiple files.
  4. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 12 Feb 2010 Link to this post

    Are you adding a RequiredFieldValidator control or a CustomValidator control? I don't think a RequiredFieldValidator control will work on RadUpload. I always use CustomValidator controls on RadUpload and I create a client-side javascript check to make sure it contains a file to upload.
Back to Top