I was hoping to set the allowed file extensions based on some chosen radio buttons, but the sample code in the on-line documentation does not work. I am weak in my javascript, so I am probably missing something simple. Here's the documentation page:
http://www.telerik.com/help/aspnet-ajax/asyncupload-client-object.html
and here's the sample code it provides:
http://www.telerik.com/help/aspnet-ajax/asyncupload-client-object.html
and here's the sample code it provides:
function
AllowJPEGExtension() {
var
upload = $find(
"<%= RadAsyncUpload1.ClientID %>"
);
if
(!upload.isExtensionValid(
".jpeg"
))
{
var
exts = upload.get_allowedFileExtensions();
exts[exts.length] =
".jpeg"
;
}
}
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 09 Apr 2013, 01:11 PM
Hi,
I guess you need to allow file extensions based on the radio button selection. Here is the code I tried from server side which worked as expected.
ASPX:
C#:
Thanks,
Princy.
I guess you need to allow file extensions based on the radio button selection. Here is the code I tried from server side which worked as expected.
ASPX:
<
asp:RadioButtonList
ID
=
"RadioButtonList1"
runat
=
"server"
RepeatDirection
=
"Horizontal"
AutoPostBack
=
"true"
OnSelectedIndexChanged
=
"RadioButtonList1_SelectedIndexChanged"
>
<
asp:ListItem
Text
=
"jpg"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"doc"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"pdf"
></
asp:ListItem
>
</
asp:RadioButtonList
>
<
br
/>
<
telerik:RadAsyncUpload
ID
=
"RadAsyncUpload1"
runat
=
"server"
>
</
telerik:RadAsyncUpload
>
C#:
protected
void
RadioButtonList1_SelectedIndexChanged(
object
sender, EventArgs e)
{
string
file = RadioButtonList1.SelectedItem.Text;
RadAsyncUpload1.AllowedFileExtensions =
new
string
[] {file};
}
Thanks,
Princy.
0

Scott
Top achievements
Rank 1
answered on 14 Apr 2013, 07:38 PM
Thank you Princy for providing a server-side solution. Does anyone have a client-side solution?
0
Accepted
Hello Scott,
Please have in mind that this can easily be overriden so if you strongly need this validation you will have to use server-side way described earlier.
Hope this will explain the issue.
All the best,
Plamen
the Telerik team
RadAsyncUpload does not support such client change in the allowed extensions because it would cause a security by providing possibility to upload unwanted files.
In your scenario since you only want to control this behavior with radio button instead of using the "AllowedFileExtensions" you can use OnClientFileUploading event and cancel the uploading file if its extension is not the desired one as in the code below:
function
OnClientFileUploading(sender, args) {
var
fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf(
'.'
) + 1, args.get_fileName().length);
alert(fileExtention);
}
Please have in mind that this can easily be overriden so if you strongly need this validation you will have to use server-side way described earlier.
Hope this will explain the issue.
All the best,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Scott
Top achievements
Rank 1
answered on 22 Apr 2013, 09:09 PM
Thank you Plamen. If possible, you may want to request a change to the documentation, since the sample code I mentioned is apparently wrong.
0
Hi Scott,
Plamen
the Telerik team
I already did this. Thank you very much for your concern with Telerik controls.
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.