Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
Let me first tell you my scenario.I am using ajax toolkit file upload control and on click of my submit button i need to check whether the file selected by the user is uploaded or not and give a error message if not.

I tried a way that once the file is selected by user then upload button visibility is coming ,by that way i done that.but now i found if user select the file and removed that.at this point also the upload button is coming .So my validation got failed.

Now i thought of getting the queue container and loop through each and every child elements and match with the remove button in that particular div.

please tell me that ,what am i doing is right? and suggest me the way to achieve this.
Posted

1 solution

Hello,

You can implement OnClientUploadComplete handler javascript function. This function is executed on the client-side after a file is uploaded successfully. You can also implement OnClientUploadError handler which gets called if there is an error in file upload.

More info on the control can be found here[^].

Update: You can use following code to retrieve the individual file names. How do you invoke it is upto you.
JavaScript
var ctrlId = '<%= AjaxFileUpload1.ClientID %>';
$('span.filename', '#' + ctrlId).each(function() {
    alert($(this).text());
});

Regards,
 
Share this answer
 
v4
Comments
hsakarp 26-Jul-13 2:07am    
Thanks Prasad Khandekar,but that event will fire only when the upload button is clicked .I need to get the status of file before itself.

Regards,
hsakarp
Prasad Khandekar 26-Jul-13 6:08am    
Please check the solution, I have updated it with a small javascript which demonstrate how you can retrieve the file names.

Regards,
hsakarp 29-Jul-13 10:10am    
Sorry for the late reply. I was on leave

Hi,

I have found this solution.Since i dont want to use Jquery.But i am facing a problem even though i am returning false the page is posting bak.How can i stop that.

note : I am using ASP.net validations in the page.

<pre lang="cs">function CheckAttachments() {
var QueueContainer = document.getElementById("AjaxFileUpload_QueueContainer");
var UploadButton = document.getElementById("AjaxFileUpload_UploadOrCancelButton");
var ErrorLabel = document.getElementById("UploadErrorMessageLabel");
var QClength = QueueContainer.children.length;
var isValid = Page_ClientValidate("");
if (isValid) {
var valid = true;
for (var i = 0; i < QClength; i++) {
var qtext = QueueContainer.childNodes[i].textContent;
if (qtext.match(/Remove/g)) {
ErrorLabel.style.visibility = "visible";
ErrorLabel.innerHTML = "Please include attachments";
valid = false;
}
}
}
}</pre>

Please help me on this.

Regards,
Hsakarp
Prasad Khandekar 30-Jul-13 3:34am    
I hope that function you have presented is a JavaScript function. If it's so when it gets called? I don't see it returning anything, except for the fact that it updates the local variable valid to false.

Regards,
hsakarp 30-Jul-13 4:13am    
Yes,the function is in javascript. I am calling the method on click of the submit button

<asp:Button ID="Button2" CausesValidation="true" Text="Close" OnClientClick="CheckAttachments()" runat="server" />

and for the value for local variable after setting it am returning that .Still i am unable to resolve this.I have copy the code below.please refer to that

function CheckAttachments() {
var QueueContainer = document.getElementById("AjaxFileUpload_QueueContainer");
var UploadButton = document.getElementById("AjaxFileUpload_UploadOrCancelButton");
var ErrorLabel = document.getElementById("UploadErrorMessageLabel");
var QClength = QueueContainer.children.length;
var isValid = Page_ClientValidate("");
if (isValid) {
var valid = true;
for (var i = 0; i < QClength; i++) {
var qtext = QueueContainer.childNodes[i].textContent;
if (qtext.match(/Remove/g)) {
ErrorLabel.style.visibility = "visible";
ErrorLabel.innerHTML = "Please click Upload to include attachments";
valid = false;
isValid = false;
return valid;
}
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900