upload cannot function

Thread is closed for posting
6 posts, 0 answers
  1. ying
    ying avatar
    27 posts
    Member since:
    May 2011

    Posted 15 Aug 2011 Link to this post

    I have  panel to contain all body
    then i use ajax to control this panel 
    Code show below
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server" >
    <AjaxSettings >
    <telerik:AjaxSetting AjaxControlID ="rblCatLevel">
    <UpdatedControls >
    <telerik:AjaxUpdatedControl ControlID ="pnlMainCat" />
    <telerik:AjaxUpdatedControl ControlID ="rblCatLevel" />
    I have a uploader inside the pnlMainCat

    when i upload file, it cannot find the find 
    i use radupload.UploadedFiles.Count , it always give me 0
    when i remove ajax, it can work properly

    <telerik:RadUpload ID="ruBanner" runat="server" EnableAjaxSkinRendering ="true"  EnableFileInputSkinning ="false" Width="50%" InitialFileInputsCount="1" ControlObjectsVisibility="None" />

    I tried this demo , but it cant work
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Aug 2011 Link to this post

    Hello Ying,

    RadUpload cannot upload files using AJAX calls. This is a limitation of the XmlHttpRequest component, used in all AJAX frameworks for asynchronous calls to the application. In order to upload a file your application must perform a full page postback.

    Check out the following help article for more on this.
    Uploading FIles with AJAX.

  3. Rayne
    Rayne avatar
    261 posts
    Member since:
    Sep 2010

    Posted 25 Oct 2011 Link to this post

    My page is using the RadAjaxManager. I've followed the suggestion to disable ajax on button click. I can run through the code, and always both InvalidFiles and UploadedFiles count is 0. I then added client-side validation for extensions. And when I click submit, I get back my validation error message about invalid extension. This is while trying to add a .jpg file. Not sure what I'm doing wrong.

    What my page is doing is getting information from the user, including up to 10 image files. Then in my submit button code, I'm using that information to create an EF entity graph (detail record with a collection of photos) and saving it to a database.
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" ClientEvents-OnRequestStart="conditionalPostback"> .... </telerik:RadAjaxManager>
    <telerik:RadUpload ID="RadUpload1" runat="server" InitialFileInputsCount="1" MaxFileInputsCount="10"
     AllowedFileExtensions=".jpg,.gif,.jpeg,.png" Skin="Simple" ReadOnlyFileInputs="true" />
    <br />
    <asp:CustomValidator runat="server" ID="ExtensionValidations" Display="Dynamic" ClientValidationFunction="validateRadUpload1" ErrorMessage="Invalid file extension" OnServerValidate="ServerValidateExtensions" />
    <telerik:RadScriptBlock runat="server">
         <script type="text/javascript">
            // on upload button click temporarily disables ajax to perform
            // upload actions
            function conditionalPostback(sender, args) {
                if (args.get_eventTarget() == "<%= SubmitButton.UniqueID %>") {
            function validateRadUpload1(source, arguments) {
                arguments.IsValid = $find("<%= RadUpload1.ClientID %>").validateExtensions();
  4. Dimitar Terziev
    Dimitar Terziev avatar
    1268 posts

    Posted 28 Oct 2011 Link to this post

    Hello Rayne,

    Please provide the server-side code that you are using.

    All the best,
    Dimitar Terziev
    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
  5. Rayne
    Rayne avatar
    261 posts
    Member since:
    Sep 2010

    Posted 28 Oct 2011 Link to this post

    The server validation is the same as in the docs:
    public void ServerValidateExtensions(object source, ServerValidateEventArgs e)
                e.IsValid = (RadUpload1.InvalidFiles.Count == 0);

    My other code is in the button click...it creates a new entity, populates it with the values from the form fields. then calls a method to get the images.

    That method is here (also following the info in the docs):
    private void MergePhotos(Submission sub)
                foreach (UploadedFile file in RadUpload1.UploadedFiles)
                    byte[] bytes = new byte[file.ContentLength];
                    file.InputStream.Read(bytes, 0, file.ContentLength);
                    Model.Photo p = new Model.Photo();
                    p.FileName = file.GetName();
                    p.Contents = bytes;
    When I break on the foreach and check the count of the collection (UploadedFiles), it's always 0.

    There's only one part of my page that needs ajax so would it help to put that part in an ajaxpanel, instead of using the ajaxmanager? The rest of the page would be outside of the ajax panel, including the radupload and the submit button.
  6. Rayne
    Rayne avatar
    261 posts
    Member since:
    Sep 2010

    Posted 31 Oct 2011 Link to this post

    I got it to work finally.
Back to Top