I have a form where a user uploads an excel file, renames the file then checks to see if the file exist. If it doesn't exist it saves fine. I get the message to overwrite if it exist, but when I click on the OK button nothing happens. How do I make this work? Thanks, I could really use your help. Here is my code:
//JavaScript Code
<script type="text/javascript" >
function Confirm()
{
window.onload = function () {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("File already exist. Do you want to overwrite?")) {
confirm_value.value = "Yes";
}
else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
document.getElementById("<%=btnSave.ClientID%>").click();
}
}
</script>
//VB.net try block from code
Try
If ext.Trim().ToLower() = "xls" Or ext.Trim().ToLower() = "xlsx" Then
saveInfo = "Original File Name: " & fileName & "<br/>"
saveInfo += "File Size: " & fuProductCapsuleEXCEL.PostedFile.ContentLength / 1000 & " Kilobytes <br/>"
saveInfo += "Content Type: " & fuProductCapsuleEXCEL.PostedFile.ContentType & "<br/>"
newFileName = salesYear + "-" + supCID + "." + ext
saveInfo += "New File Name: " + newFileName.ToString()
'check if file already exist
exist = CheckForDup(newFileName)
'if file doesent exist, add it to folder
If exist = False Then
fuProductCapsuleEXCEL.SaveAs(Application("IMARK_RootPath") & "/UPLOADED_FILE/G2G_SKUs/" + newFileName)
lblSaveInfo.Text = saveInfo.ToString()
End If
'file with newfilename already in folder. Check for overwrite
If exist = True Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), "confirm", "Confirm()", True)
End If
End If
Catch ex As Exception
Throw ex
End Try
//JavaScript Code
<script type="text/javascript" >
function Confirm()
{
window.onload = function () {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("File already exist. Do you want to overwrite?")) {
confirm_value.value = "Yes";
}
else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
document.getElementById("<%=btnSave.ClientID%>").click();
}
}
</script>
//VB.net try block from code
Try
If ext.Trim().ToLower() = "xls" Or ext.Trim().ToLower() = "xlsx" Then
saveInfo = "Original File Name: " & fileName & "<br/>"
saveInfo += "File Size: " & fuProductCapsuleEXCEL.PostedFile.ContentLength / 1000 & " Kilobytes <br/>"
saveInfo += "Content Type: " & fuProductCapsuleEXCEL.PostedFile.ContentType & "<br/>"
newFileName = salesYear + "-" + supCID + "." + ext
saveInfo += "New File Name: " + newFileName.ToString()
'check if file already exist
exist = CheckForDup(newFileName)
'if file doesent exist, add it to folder
If exist = False Then
fuProductCapsuleEXCEL.SaveAs(Application("IMARK_RootPath") & "/UPLOADED_FILE/G2G_SKUs/" + newFileName)
lblSaveInfo.Text = saveInfo.ToString()
End If
'file with newfilename already in folder. Check for overwrite
If exist = True Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), "confirm", "Confirm()", True)
End If
End If
Catch ex As Exception
Throw ex
End Try