extending AsyncUpload control

8 posts, 0 answers
  1. Arun
    Arun avatar
    8 posts
    Member since:
    Mar 2014

    Posted 29 May 2014 Link to this post

    Hi I want to extend RadAsyncUpload control to meet our
    custom validation need. However, I am experiencing two issues here.

    1.  RadAsyncUpload contains two controls, one is
    textbox and other is a button to invoke file explorer. However, to show error
    how can I only target the textbox and not the button? Say for example, I want
    to change only textbox border color when its invalid (and not the button)

     

    2.  In extended control’s PreRender,  when I change CssClass attribute of the
    control  if control is invalid, the change doesn't reflect on the control, but when I change the CssClass attribute before
    the condition (if valid), the change takes effect. So looks like I can’t change the style
    attribute after first load, which is very strange. However, I am not sure why
    this is happening

    Hope someone can help me with this.

    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 May 2014 in reply to Arun Link to this post

    Hi Arun,

    Please try to attach the OnClientValidationFailed event of RadAsyncupload and style the TextBox as follows.

    JavaScript:
    function Validation(sender, args) {
        document.getElementsByClassName("ruFakeInput radPreventDecorate").RadAsyncUpload1fakeInput1.style.borderColor = "Red";
    }

    I am not sure about your second requirement. Please have a look into the sample code snippet to change the border color of the RadAsyncUpload. If an invalid file is uploading it will not persist after post back but the style that given in PreRender event will persist.

    C#:
    protected void RadAsyncUpload1_PreRender(object sender, EventArgs e)
    {
        RadAsyncUpload1.Style.Add("border", "1px solid red");
    }

    Let me know if you have any concern.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Arun
    Arun avatar
    8 posts
    Member since:
    Mar 2014

    Posted 30 May 2014 in reply to Shinu Link to this post

    Hi Shinu thank you for your response. I tried as you suggested. However, when following code block get executed. The control (radAsyncUpload) get invisible. Not sure why.

    function Validation(sender, args) {
        document.getElementsByClassName("ruFakeInput radPreventDecorate").RadAsyncUpload1fakeInput1.style.borderColor = "Red";
    }

    On second issue. Here is my problem

    protected override void OnPreRender(EventArgs e)<br> { <br>   this.Style.Add("border", "1px solid red");  //This Works <br><br>   if (hasError){<br><br>         this.Style.Add("border", "1px solid red");  //This does NOT WORK<br>    <br>   }<br><br>}


    I am not sure, why this is happening. Is there a remedy?
    Thanks
    Arun
  5. Arun
    Arun avatar
    8 posts
    Member since:
    Mar 2014

    Posted 30 May 2014 Link to this post

    Hi Shinu, sorry formatting of the previous post got messed up. So I am posting second part again

    On second issue. Here is my problem

    protected override void OnPreRender(EventArgs e)
     {
                base.OnPreRender(e);
     
                this.Style.Add("border", "1px solid red"); //This works
     
                 if (hasError){
     
                    this.Style.Add("border", "1px solid red"); //This does NOT work
     
               }
     
    }

    I am not sure, why this is happening. Is there a remedy?

    Thanks

    Arun
  6. Arun
    Arun avatar
    8 posts
    Member since:
    Mar 2014

    Posted 30 May 2014 Link to this post

    Hi Shinu, I was able to resolve the first issue, but there
    is no point, if I can’t resolve the second one, because I have to change the
    control on postback (on submit), and as I said, it doesn’t change anything on
    post back. Simply nothing happen.
    Thanks,
    Arun
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Jun 2014 in reply to Arun Link to this post

    Hi Arun,

    RadAsyncUpload provides client-side event called OnClientValidationFailed. It is fired when an Invalid File is trying to upload. For the server side validation you can use the FileUploaded event which will fire separately for each and every uploaded file. Each file can be marked as a valid or invalid using the IsValid property of FileUploadedEventArgs. If the file is validate from the client side  itself will not get on the server side, it will not persist after post back.  Please have a look into this online demo which shows the validation of RadAsyncUpload.

    Thanks,
    Shinu.
  8. Arun
    Arun avatar
    8 posts
    Member since:
    Mar 2014

    Posted 02 Jun 2014 Link to this post

    Hi Shinu, I am extending control like this "public class AsyncUpload : RadAsyncUpload" and lets say if I want to check from server side if a file is uploaded or not and display error (as showed in the in the code in OnPreRender), without using "OnClientValidationFailed" how can I do that? Or it can't be done at all? I think the way I am implementing it, I want control to be validated after form submit.

     We extended all other controls like that, and they are working fine. Why this approach won't work for this control?
    Thanks for your help
    Regards
    Arun
  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Jun 2014 in reply to Arun Link to this post

    Hi Arun,

    Validation for RadAsyncUpload differs from validation in RadUpload as it is now possible to validate size on the client.  OnFileUploaded event you can mark a file as valid or invalid using the IsValid property. AllowedFileExrensions and MaxFileSize these validation will check from the client side itself and the invalid file will not get it on the server side. It is not possible to get the Invalid File on the server side this is the default behavior of the control.

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017