Problems uploading files

E

Er bengaor

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('output').value =
this.value;">
<input type="text" id="output" class="editor">
<input class="botones" type="button" value="Browse"
onClick="javascript:document.getElementById('txtImagePreview').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>
 
K

Kevin Spencer

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.
 
J

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
 
K

Kevin Spencer

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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top