document.forms[0].submit() --- please help

R

Richard

Hi,
I want to have only one button to Upload file but i get Access denied
error.
Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
FileUpload1.Attributes.Add("onchange",
"document.forms[0].submit();");
}

Default.aspx:
<head>
<script language="javascript" type="text/javascript">
function FileUpload1Click(){
document.getElementById("FileUpload1").click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" onclick="javascript:FileUpload1Click();"
value="Attach file" runat="server" />
<input type="file" id="FileUpload1" runat="server"
style="display:none;" />
</form>
</body>
</html>

Is there a way of doing this with one click button only?
Any suggestions?
Richard
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Not clear where your error is,

First, all your code is javascript, where is C# involved?

what you mean with one button to upload?

How will the user select teh file if he cannot see the file control.

Additionally the form is missing ENCTYPE="multipart/form-data"
this is needed when you are uploading a file
 
R

Richard

Hi,
Thank's for a reply.
My error is when i want to do this:
document.forms[0].submit()

my c# code in this example is only here:
protected void Page_Load(object sender, EventArgs e)
{
FileUpload1.Attributes.Add("onchange",
"document.forms[0].submit();");
}
but whole rest of the project is in c# (this is only working short
example of my error).
I just want to have only one button on the page, if you will click it
then "file open dialog pop ups, you select a file, click open, and
that's all (there is no visible textbox with path + browse button and
there is no need to submit button after all).
Can you help me with this please?

Richard
 

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

Top