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

Allowed file extensions not working in grid edit mode

1 Answer 98 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Kirk Thomas
Top achievements
Rank 1
Kirk Thomas asked on 19 Oct 2009, 03:10 PM
Hello,

I have a radupload in a radgrid's edit form template and I've set the allowed file extensions in the properties window as well as set them in the validating file event method.  I also have a radupload in a form on my page outside of the grid and I don't think the allowed file extensions property worked correctly with that one either but it didn't matter because I have java script that I use in a custom validator  that took care of that along with making the upload a required field.  Do I have to have java script and the custom validator to have the allowed file extensions property to work or should I just have to set the files to be allowed in the property window?  If I do need to use the java script and custom validator how do I find a control that is in a grid's edit form template using javascript?

Thanks for the help,
Kirk

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 22 Oct 2009, 02:17 PM
Hi Kirk Thomas,

The AllowedExtensionsProperty does its job on the server, not on the client. When you upload files whose extensions do not match the allowed ones, those files are moved to the InvalidFiles collection rather to the UploadedFiles one. To sum up, once you have set the AllowedExtensionsProperty you can obtain the valid files using the UploadedFiles collection. The invalid ones can be found in their respective InvalidFiles collection.

However, you can do the validation (with ASP Validator) on the client as well. As far as I can see this is the way you proceed. In order to to that validation you need to have set the server-side AllowedExtensionsProperty. When the page is rendered, that property is serialzed on the client and you can use it using the validateExtensions() method of the RadUpload. The correct way to find the RadUpload instance that is i the grid's edit form template is:

1) Hook on the ItemDataBound event of the RadGrid and add the following code:

void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        RadUpload upload = e.Item.FindControl("RadUpload1") as RadUpload;
        Page.RegisterClientScriptBlock("Upload", string.Format("window['UploadId'] = '{0}';", upload.ClientID));
    }
}

2) use the following JavaScript function:

function validateRadUpload1(source, arguments)
{
  var upload = $find(window['UploadId']);
 arguments.IsValid = upload.validateExtensions();
}




Sincerely yours,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Upload (Obsolete)
Asked by
Kirk Thomas
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or