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

extending AsyncUpload control

7 Answers 78 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Arun
Top achievements
Rank 1
Arun asked on 29 May 2014, 11:49 PM
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

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 May 2014, 05:21 AM
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.
0
Arun
Top achievements
Rank 1
answered on 30 May 2014, 02:12 PM
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
0
Arun
Top achievements
Rank 1
answered on 30 May 2014, 02:17 PM
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
0
Arun
Top achievements
Rank 1
answered on 30 May 2014, 08:38 PM
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
0
Shinu
Top achievements
Rank 2
answered on 02 Jun 2014, 03:28 AM
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.
0
Arun
Top achievements
Rank 1
answered on 02 Jun 2014, 02:30 PM
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
0
Shinu
Top achievements
Rank 2
answered on 03 Jun 2014, 03:41 AM
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.
Tags
AsyncUpload
Asked by
Arun
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Arun
Top achievements
Rank 1
Share this question
or