By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Problems uploading files

P: n/a
Hi.

I am trying to simulate the fileupload html control in order to use
different css styles in the editbox and button. To do this, I'm using a
hidden fileupload control and javascript. But when I first click the web
control button to send the file, the value of this hidden control is
deleted without doing the postback to the server. Does anybody knows
what it happens? Thank you in advance.

This is my code:

<asp:TableRow>
<asp:TableCell>
<input id="txtImagePreview" runat="server"
type="file" style="DISPLAY: none"
onchange="javascript:document.getElementById('outp ut').value =
this.value;">
<input type="text" id="output" class="editor">
<input class="botones" type="button" value="Browse"
onClick="javascript:document.getElementById('txtIm agePreview').click()"
style="height: 20px; width: 56px;">
</asp:TableCell>
<asp:TableCell HorizontalAlign="Left">
<asp:Button runat="server" Width="56px" ID="btnUploadFile"
height="20px"
Text="Upload" CssClass="botones"></asp:Button>
</asp:TableCell>
</asp:TableRow>
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I'm afraid you're going about it all wrong. You can't programmatically set
the value of an "input type=file" HTML Element, hidden or no. The only way
to set what file is going to be uploaded is by setting the value in the
visible box using the Browse Button, or by typing it in, neither of which is
possible with a hidden form field. This is by design. I believe it is a
security precaution, to prevent web sites from taking files from the user's
machine without permission.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Er bengaor" <ju******@hotmail.com> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Hi.

I am trying to simulate the fileupload html control in order to use
different css styles in the editbox and button. To do this, I'm using a
hidden fileupload control and javascript. But when I first click the web
control button to send the file, the value of this hidden control is
deleted without doing the postback to the server. Does anybody knows
what it happens? Thank you in advance.

This is my code:

<asp:TableRow>
<asp:TableCell>
<input id="txtImagePreview" runat="server"
type="file" style="DISPLAY: none"
onchange="javascript:document.getElementById('outp ut').value =
this.value;">
<input type="text" id="output" class="editor">
<input class="botones" type="button" value="Browse"
onClick="javascript:document.getElementById('txtIm agePreview').click()"
style="height: 20px; width: 56px;">
</asp:TableCell>
<asp:TableCell HorizontalAlign="Left">
<asp:Button runat="server" Width="56px" ID="btnUploadFile"
height="20px"
Text="Upload" CssClass="botones"></asp:Button>
</asp:TableCell>
</asp:TableRow>

Nov 18 '05 #2

P: n/a
JC
Thank you for your response, Kevin.

I knew the limitation of the fileupload element but I don't assign the
value of the element programatically in my code. I only call the click
event handler to show the file selection dialog.

Thank you again,
jc

Kevin Spencer wrote:
I'm afraid you're going about it all wrong. You can't programmatically set
the value of an "input type=file" HTML Element, hidden or no. The only way
to set what file is going to be uploaded is by setting the value in the
visible box using the Browse Button, or by typing it in, neither of which is
possible with a hidden form field. This is by design. I believe it is a
security precaution, to prevent web sites from taking files from the user's
machine without permission.


Nov 18 '05 #3

P: n/a
If the form field is hidden, you won't be able to call the Click event, or
see any file selection dialog.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"JC" <ju******@hotmail.com> wrote in message
news:#d**************@TK2MSFTNGP09.phx.gbl...
Thank you for your response, Kevin.

I knew the limitation of the fileupload element but I don't assign the
value of the element programatically in my code. I only call the click
event handler to show the file selection dialog.

Thank you again,
jc

Kevin Spencer wrote:
I'm afraid you're going about it all wrong. You can't programmatically set the value of an "input type=file" HTML Element, hidden or no. The only way to set what file is going to be uploaded is by setting the value in the
visible box using the Browse Button, or by typing it in, neither of which is possible with a hidden form field. This is by design. I believe it is a
security precaution, to prevent web sites from taking files from the user's machine without permission.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.