RichardRiga
asked on
Using AJAX.NET how do you clear an uploadfile control?
I have a regular upload file control inside an AJAX.NET updatepanel. If I use it to upload a file once, its no problem; however, if i hit the submit button again, even though the text box is clear, it is still attached to the previous file uploaded.
How do I clear that so that I may use the uploadfile control freshly?
How do I clear that so that I may use the uploadfile control freshly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
regarding to Ur question
but a JavaScript function to see if the file upload is empty
var FileUpload1="<%=FileUpload 1.ClientID %>"
function CheckForTestFile()
{
var file = document.getElementById(Fi leUpload1) ;
var fileName=file.value;
//Checking for file browsed or not
if (Trim(fileName) =='' )
{
alert("Please select a file to upload!!!");
file.focus();
return false;
}
}
and on ur button
add this
<asp:Button ID="btnUpload" runat="server" OnClientClick="if(CheckFor TestFile() ){return true}else{return false}"
text="Upload File" TabIndex="50" EnableViewState="False" />
but a JavaScript function to see if the file upload is empty
var FileUpload1="<%=FileUpload
function CheckForTestFile()
{
var file = document.getElementById(Fi
var fileName=file.value;
//Checking for file browsed or not
if (Trim(fileName) =='' )
{
alert("Please select a file to upload!!!");
file.focus();
return false;
}
}
and on ur button
add this
<asp:Button ID="btnUpload" runat="server" OnClientClick="if(CheckFor
text="Upload File" TabIndex="50" EnableViewState="False" />
ASKER
These methods don't seem to work still. I have inserted them into the proper places and they are being executed; however, the fileupload control still reports that it has contents when trying to upload a blank file'
ASKER
My apologies!! I completely forgot to mention that I wasn't using an ASP:FileUpload control. I'm using the AsyncFileUpload control from the AjaxToolkit. I'm not sure it makes a difference in your answers;however, I should have added that.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is what happens:
1. I use the control to upload a file. That works, no problem.
At this point the control's field resets itself to appear empty.
Since the field is empty, at this point, if I hit the submit button again, the property fuFileUpload.HasFile should be False. But its not. It returns true.
2. So i use a script:
function clearContents() {
var AsyncFileUpload = $get("<%=fuFileUpload.ClientID%>");
var txts = AsyncFileUpload.getElementsByTagName("input");
for (var i = 0; i < txts.length; i++) {
if (txts[i].type == "text") {
txts[i].value = "";
txts[i].style.backgroundColor = "white";
}
}
}
and call on that script when the file is uploaded with:
<cc1:AsyncFileUpload ID="fuFileUpload" runat="server" OnClientUploadComplete="<%UploadComplete() %>" />
Codebehind has:
Public Sub CallUploadComplete()
ClientScript.RegisterStartupScript(Me.GetType(), "removeDoc", "ClearContents()", True)
End Sub
Something isn't right. Can anyone fix those three snippets of code to make it work? I beg!
And thanks.
What does the
IsNothing(fuFileUpload.Pos tedFile)
return?
IsNothing(fuFileUpload.Pos
return?
ASKER
Project was scrapped. Apologies for the waste of time, but thank you for being respondent
ASKER