Required Field Validator on RadUpload in RadGrid Template Column

2 posts, 0 answers
  1. Bruce Parr
    Bruce Parr avatar
    11 posts
    Member since:
    Feb 2009

    Posted 14 Dec 2010 Link to this post


    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?

  2. Craig Mellon
    Craig Mellon avatar
    53 posts
    Member since:
    May 2005

    Posted 14 Dec 2010 Link to this post

    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
    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))
    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
  3. DevCraft R3 2016 release webinar banner
Back to Top