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);
}
}
}
<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()" />
<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" />