471,092 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

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

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

May 8 '06 #1
2 6779
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
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Richard" <se****@interia.pl> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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

May 8 '06 #2
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

May 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Chris | last post: by
8 posts views Thread by Ed Jay | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.