asp:FileUpload and a non-submit button results in js "Access Denie

G

Guest

I'm trying to upload a file using an asp:FileUpload control and an
asp:LinkButton.
This works fine, while there is an actual filepath in the fileupload upload
control. Even an empty field works. But a bogus filename results in the
"Access Denied" javascript error in IE7.

This also happens when I use an asp:Button with the UseSubmitBehavior
property set to false. When the UseSubmitBehavior is set to true (default),
the button does nothing. This isn't what I want either. Because I want it to
submit so I can check the .HasFile property and show an error message.

It seems that the added javascript submit code triggers IE7 security
routines that come with input type="file".

Is there a way to solve this?

This is the sample code I used:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="FileUploadTest._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:FileUpload ID="fuUpload" runat="server" />
<br />

<asp:LinkButton id="btnLinkButton" runat="server"
OnClick="btnUpload_Click" Text="Fails" />
<br />

<asp:Button ID="btnSubmitButton" runat="server" OnClick="btnUpload_Click"
Text="Does nothing" />
<br />

<asp:Button ID="btnButton" runat="server" OnClick="btnUpload_Click"
Text="Fails" UseSubmitBehavior="false" />
<br />

<asp:Label ID="lblResult" runat="server" />
</div>
</form>
</body>
</html>

pagebehind:
amespace FileUploadTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load ( object sender, EventArgs e )
{

}

protected void btnUpload_Click ( object sender, EventArgs e )
{
if (fuUpload.HasFile)
{
lblResult.Text = "Upload Succeeded";
}
else
{
lblResult.Text = "Upload Failed";
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top