Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using fileupload control in my asp.net application. But this control add a default upload button browse and a textbox where path is shown after selecting file.Onclick of browse button I am uploading the file and clicking on submit button.For the first time,On click of submit button, the uploaded file is automatically deleting and unable to submit the form.On click of Submit button I am able to submit the button.

I did n't understand why the file is automatically deleting.It works fine in the local system.When i copy then files in test server.This issue rises.

What I have tried:

function DisplayFileDescription() {

var tb1 = document.getElementById("<%=txtCourseCode.ClientID %>").value;
var tb2 = document.getElementById("<%=txtExamNumber.ClientID %>").value;

if (tb1 == '') {
document.getElementById("<%=rfvCourseCode.ClientID%>").style.visibility = "visible";
document.getElementById("<%=rfvCourseCode.ClientID%>").enabled = true;
// Clear();
}
if (tb2 == '') {
document.getElementById("<%=rfvExamNumber.ClientID%>").style.visibility = "visible";
document.getElementById("<%=rfvExamNumber.ClientID%>").enabled = true;
// Clear();
}
if(tb1!='' && tb2!='') {
document.getElementById("<%=rfvCourseCode.ClientID%>").style.visibility = "hidden";
document.getElementById("<%=rfvCourseCode.ClientID%>").enabled = false;
document.getElementById("<%=rfvExamNumber.ClientID%>").style.visibility = "hidden";
document.getElementById("<%=rfvExamNumber.ClientID%>").enabled = false;
}

//var strcollege = document.getElementById("ctl00$ContentPlaceHolder1$ddlCollege").options[e.selectedIndex].text;
var College = document.getElementById("ddlCollege");
var strcollege = College.options[College.selectedIndex].text;

//UI Studnet
if (strcollege == "University of Iowa") {
var strFileDescription = document.getElementById('<%=txtCourseCode.ClientID %>').value;
// var strFileDescription = document.getElementById('<%=txtCourseCode.ClientID %>').value + "_" + document.getElementById('<%=txtExamNumber.ClientID %>').value;

//strFileDescription = removeSpecial(strFileDescription);
strFileDescription = strFileDescription.split(':').join("");
document.getElementById('<%=txtFileDescription.ClientID%>').value = strFileDescription;

if (document.getElementById("FileUploadAttachment").value != '') {
var filename = document.getElementById("FileUploadAttachment").value;

document.getElementById("lblFileChoosen").innerHTML = filename.substring(filename.lastIndexOf('\\') + 1);

}
}
//Non UI Student
else {
var strFileDescription = document.getElementById('<%=txtStudentFirstName.ClientID %>').value + document.getElementById('<%=txtStudentLastName.ClientID %>').value + "_" +
document.getElementById('<%=txtCourseCode.ClientID %>').value + "_" + document.getElementById('<%=txtExamNumber.ClientID %>').value;

strFileDescription = strFileDescription.split(':').join("");
document.getElementById('<%=txtFileDescription.ClientID%>').value = strFileDescription;

if (document.getElementById("ContentPlaceHolder1_FileUploadAttachment").value != '') {
var filename = document.getElementById("ContentPlaceHolder1_FileUploadAttachment").value;

document.getElementById("lblFileChoosen").innerHTML = filename.substring(filename.lastIndexOf('\\') + 1);
}
}

}
ASP.NET
<table runat="server" id="tblExamFileAttachments" frame="box" visible="false" width="800px"
                              cellpadding="0" cellspacing="0">
                              <tr>
                                  <td width="10px">
                                  </td>
                                  <td style="font-weight: bold" colspan="2">
                                      Upload Exam Attachment File
                                      <br />
                                      <br />
                                  </td>
                              </tr>
                              <tr>
                                  <td width="10px">
                                  </td>
                                  <td style="font-weight: bold">
                                      Please select File :
                                  </td>
                                  <td>
                                      <asp:FileUpload ID="FileUploadAttachment" runat="server" size="50" onchange="DisplayFileDescription()" />&nbsp;
                                      <asp:Label ID="lblFileChoosen" runat="server" Text=""></asp:Label>
                                  </td>
                              </tr>
                              <tr>
                                  <td width="10px">
                                  </td>
                                  <td style="font-weight: bold">
                                      File Description:
                                  </td>
                                  <td>
                                      <asp:TextBox runat="server" Width="300px" ID="txtFileDescription">
                                      </asp:TextBox>
                                  </td>
                              </tr>
                          </table>


<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"
Font-Bold="true" CssClass="SubmitButton" ValidationGroup="SubmitGroup" />
Posted
Updated 17-Oct-16 21:55pm

What you were seeing is normal, and it's because for security reasons. Searching for it in the web why it does that behavior will give you loads of results. Here's one short discussion: asp.net - FileUpload control clears itself - Stack Overflow[^]

You may need to switch to a client-side based file uploading if you don't want to be bothered by postbacks.
 
Share this answer
 
v2
ASP.NET
  <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>

<table runat="server" id="tblExamFileAttachments" frame="box" visible="false" width="800px"
                              cellpadding="0" cellspacing="0">
                              <tr>
                                  <td width="10px">
                                  </td>
                                  <td style="font-weight: bold" colspan="2">
                                      Upload Exam Attachment File
                                      <br />
                                      <br />
                                  </td>
                              </tr>
                              <tr>
                                  <td width="10px">
                                  </td>
                                  <td style="font-weight: bold">
                                      Please select File :
                                  </td>
                                  <td>
                                      <asp:FileUpload ID="FileUploadAttachment" runat="server" size="50" onchange="DisplayFileDescription()" />&nbsp;
                                      <asp:Label ID="lblFileChoosen" runat="server" Text=""></asp:Label>
                                  </td>
                              </tr>
                              <tr>
                                  <td width="10px">
                                  </td>
                                  <td style="font-weight: bold">
                                      File Description:
                                  </td>
                                  <td>
                                      <asp:TextBox runat="server" Width="300px" ID="txtFileDescription">
                                      </asp:TextBox>
                                  </td>
                              </tr>
                          </table>
                          </ContentTemplate>
                           <Triggers>
       <asp:PostBackTrigger ControlID="btnSubmit" />
       </Triggers>
                          </asp:UpdatePanel>
 
Share this answer
 
v2

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