473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

using the HtmlInputFile

nes

Hi all,

For uploading files i am using the HtmlInputFile. Now I want to do 2
things with it. First I want to give the button a specific style and
second when a postback happens I don't want the selected file to
disappear from the HtmlInputFile.
Now on the web I found the next thing:

<html>
<head>
<title>File Upload Example</title>
<script language="JavaScript" type="text/javascript">
function HandleFileButtonClick()
{
document.frmUpload.myFile.click();
document.frmUpload.txtFakeText.value =
document.frmUpload.myFile.value;
}
</script>
</head>
<body>
<form name="frmUpload">
<!-- Real Input field, but hidden-->
<input type="file" name="myFile" style="display: none">
<!-- Fake field to fool the user -->
<input type="text" name="txtFakeText" readonly="true">
<!-- Button to invoke the click of the File Input -->
<input type="button" onclick="HandleFileButtonClick();"
value="Upload File" style="background: red;">
</form>
</body>
</html>

Now this works really perfect. You don't really use the htmlInputfile
but separate button and textbox so you can give your style and you have
the file name showing.

My problem is that I have an ASP:BUTTON for Submitting my file (some
reading, changing, ...) But when you click the button for the first
time it erases the value from the HtmlInputFile. So you have to press
again for really doing your submit code.
You don't have that problem when you are using a HtmlInputButton(if you
use clientscript), but unfortunately I can't use it.
Has anyone got a suggestion how I can resolve the problem of have to
press the button twice?

Thx

Nes
--
nes
------------------------------------------------------------------------
nes's Profile: http://www.highdots.com/forums/m1723
View this thread: http://www.highdots.com/forums/t3198457

Jan 12 '06 #1
1 1677
I've struggled with this one myself in the past. Unfortunately, I found
that the best thing to do was to leave the file input alone and just
let it be :|

It seems the clearing of the input type=file (ITF from now on) when the
form is submitted is an IE security feature. The only way to avoid this
is to ACTUALLY click on the ITF's browse button or enter the path
directly. It has nothing to do with ASP.NET - you can recreate it in
plain old html.

Furthermore, the script doesn't work at all in Firefox et al.

Finally, the user wouldn't be able to re-upload the file a second time
just because you kept the value in txtFakeText. You'd need to put that
value back into the ITF when the page reloaded, and as I'm sure you're
aware, that's just not possible (and with good security reasons!)

Let me know if you find an amazing solution though!

HTH

Josh
http://www.thejoyofcode.com/

Jan 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: R Reyes | last post by:
I am coding a forum and am having problems passing around the attachment file (as an HtmlInputFile) from page to page. Sometimes the users may want to preview their posts with the attachment specs...
1
by: Newbie | last post by:
i have a c# asp.net webform that has an HtmlInputFile and a listbox (to hold the filenames to be uploaded). but HtmlInputFile.PostedFile and HtmlInputFile.Value are readonly properties. i have to...
9
by: Rob Meade | last post by:
Hi all, I've got some code here that builds a page dynamically, ie, added a table, rows, cells, controls in the cells and so on... Everything has gone fine until now, I need to add a 'File...
2
by: Augusto Cesar via DotNetMonster.com | last post by:
Hi, I want to customize the HtmlInputFile. I wanna something like an image button to play the "browse" button hole and hide the textbox. Is that possible? I also have tried to hide an...
3
by: UJ | last post by:
Guys, I know this isn't the appropriate place to post this because it's HTML not ASP.Net but I need some guidance. I have a web page with an HTMLInputFile on it. The person enters the stuff,...
7
by: Buddy Ackerman | last post by:
I created this class Public Class HTMLFileInput : Inherits System.Web.UI.HtmlControls.HtmlInputFile Public Property Data As String Get Return ViewState("HTMLFileInput.Data") End Get Set...
3
by: Dave Adler | last post by:
Is there any way to retain the value of an HtmlInputFile control through a postback? I do some server side validation on the page when it is submitted and if an error occurs on the page the...
8
by: Nathan Sokalski | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. After the file is successfully submitted, I want the field to be reset so that the user knows the file was...
4
by: Chris | last post by:
Hello, I am using asp.net. I have been searching this for a while, but dint find any solution yet. Any help will be appreciated. I have a string variable say 'myFile' that has complete path of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.