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

Required Field Validator on RadUpload in RadGrid Template Column

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce Parr
Top achievements
Rank 1
Bruce Parr asked on 14 Dec 2010, 02:08 PM
All,

I am trying to figure out a way of requiring a file to be uploaded when doing an insert. I have the plumbing all connected in the ItemCreated event of the grid, but I can't seem to hook the RequiredFieldValidator to the RadUpload control in the Edit template.

I thought about using a custom validator instead, but I still can't seem to figure out how to get a hold of the RadUpload control in the custom validator event.

Can anyone provide some suggestions and snippets to get me past this?

Thanks,
jax

1 Answer, 1 is accepted

Sort by
0
Craig Mellon
Top achievements
Rank 1
answered on 14 Dec 2010, 02:46 PM
Ignore if this is not what you need but could you not use the following in the ItemCreated event?

If RadUpload1.UploadedFiles.Count > 0 Then
  
'System.Threading.Thread.Sleep(3000)
  
Else
  
lblMsg.Text = "You have not selected a Photo to upload."
  
lblMsg.CssClass = "lblHeaderRed"
  
Exit Sub
  
End If
  
If RadUpload1.InvalidFiles.Count > 0 Then
  
For Each f As UploadedFile In RadUpload1.InvalidFiles
  
If f.ContentLength > RadUpload1.MaxFileSize Then
  
lblMsg.Text = String.Format("The file you have tried to upload has exceeded the maximum file size allowed.<br>File name: {0}<br>File extension {1}<br>File Content type: {2}<br>File Size: {3} MB", f.GetName(), f.GetExtension(), f.ContentType, Math.Round(Convert.ToDouble((f.ContentLength / 1024) / 1024), 2))
  
Else
  
lblMsg.Text = String.Format("<b>The file you have tried to upload is not a valid photo file.</b> <br> Allowed File Extensions: .jpg, .jpeg, .png, .gif, .bmp<br>File name: {0}<br>File extension {1}<br>File Content type: {2}", f.GetName(), f.GetExtension(), f.ContentType)
  
End If
  

and just use the FindControl method to find the RADUpload, something like this:

For Each c2 As Control In RadGrid
    If c2.GetType.ToString = "Telerik.Web.UI.RadUpload" Then
     *Above code here*
    End If
Exit For
Next
Tags
Grid
Asked by
Bruce Parr
Top achievements
Rank 1
Answers by
Craig Mellon
Top achievements
Rank 1
Share this question
or