473,657 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript" type="text/javascript">
function HandleFileButto nClick()
{
document.frmUpl oad.myFile.clic k();
document.frmUpl oad.txtFakeText .value =
document.frmUpl oad.myFile.valu e;
}
</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="txtFakeTe xt" readonly="true" >
<!-- Button to invoke the click of the File Input -->
<input type="button" onclick="Handle FileButtonClick ();"
value="Upload File" style="backgrou nd: 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 1688
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
2947
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 (filesize, content-type, etc..) before submitting. i have tried storing it in a session like so: HtmlInputFile uploadFile = new HtmlInputFile(); Session = uploadFile.PostedFile; Then retrieving it, though I can't seem to figure out if the...
1
2122
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 populate the listbox prior to showing it to the user. the listbox will already contain items (old files) in it when the user first see it. i am trying to add files to the HtmlInputFile collection programmatically before letting the user add or...
9
1677
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 Input' box (ie, the HTML <input type="file"> etc), I've got this: Dim txtFile as HtmlInputFile
2
1667
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 HtmlInputFile in my page and added some javascript code to a button to fire the click() event of the HtmlInputFile. It worked for a moment, but when the submit button is clicked the HtmlInputFile looses its value. This solution was described in the...
3
4731
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, that's all great. They go to the next page and I allow them to click a button to go back a page to change values. When I go back one page, I want the HTMLInputFile to be filled in with the previously loaded value (which I have saved somewhere) but...
7
1756
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 (ByVal Value As String)
3
4555
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 HtmlInputFile control value is blank after the postback. The EnableViewState for the control is set to true. I can't put the postedFile.filename value in a hidden control and then put it back into the HtmlInputFile control on postback because the...
8
1855
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 submitted. However, ASP.NET does not let you change the Value property of an HtmlInputFile control. How can I reset the HtmlInputFile control to it's original state? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
4
1933
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 a file located in client machine. eg: Dim myFile as string = "C:/myFolder/File1.txt" Clicking on a button should copy that file from local client to a
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.