473,405 Members | 2,334 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,405 software developers and data experts.

Help with HtmlInputFile question?

Hi - I'm a newbie to .NET and I was hoping someone would be so kind as to
help me out with a question?

Specifiec in my .aspx file: <input type="file" size="50" id="FileToSend"
runat="server" NAME="FileToSend"> and in my class as: protected System.Web.UI.
HtmlControls.HtmlInputFile FileToSend;

When the user clicks the Browse... button, chooses a file and clicks Open,
I'd like to be able to "intercept" the File before it is displayed in the
(input) field?

That way I could add the File to a running list of Files they would like to
Add/Upload. The AOL (web) Mail system allows multi-file uploads this way -- I
was just trying to see if I could do the same?

Thanks for any help!

Larry
Nov 19 '05 #1
13 1242
Larry,

You could attach a ontextchanged javascript to the input that would take the
text in the input and add it to a list box.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Larry O via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:54***********@DotNetMonster.com...
Hi - I'm a newbie to .NET and I was hoping someone would be so kind as to
help me out with a question?

Specifiec in my .aspx file: <input type="file" size="50" id="FileToSend"
runat="server" NAME="FileToSend"> and in my class as: protected
System.Web.UI.
HtmlControls.HtmlInputFile FileToSend;

When the user clicks the Browse... button, chooses a file and clicks Open,
I'd like to be able to "intercept" the File before it is displayed in the
(input) field?

That way I could add the File to a running list of Files they would like
to
Add/Upload. The AOL (web) Mail system allows multi-file uploads this
way -- I
was just trying to see if I could do the same?

Thanks for any help!

Larry

Nov 19 '05 #2
Thanks for the suggestion.

So if you don't mind, a bit more detail?

If in my .ascx "html" code I add something like: <input onchange="javascript:
Changed( this );" type="file" ...
I can get the javascript function to fire but how can I update the WebControl
and then get the page to redisplay? For example, in my UserControl class (in
my .ascx.cs file) I have the following definition:

protected System.Web.UI.WebControls.TextBox Name;

We'll say I would like the javascript() to update this Name control and then
"refresh" the page? It doesn't seem that I can do this, right? (note that the
alert does work)

<script language="javascript">
function Changed( textControl )
{
alert( textControl.value );
Name.Text = textControl.value;
}
</script>

Thanks again for the help!

Larry

S. Justin Gengo wrote:
Larry,

You could attach a ontextchanged javascript to the input that would take the
text in the input and add it to a list box.
Hi - I'm a newbie to .NET and I was hoping someone would be so kind as to
help me out with a question?

[quoted text clipped - 17 lines]

Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1
Nov 19 '05 #3
Larry,

You'll need to look up a bit of javascript, but you can assign values to any
control on the page via javascript. So you could get the file path, add it
to a list box, and then delete the file path from the original input. I
wouldn't even worry about posting back until after your user has entered all
the files. Then give them a button to save the files that does the post back
after the list is complete.

To get you started here's the javascript to add an item to a listbox:

listbox.options[listbox.options.length] = new Option("Test", 15, false,
false);

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Larry O via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:54***********@DotNetMonster.com...
Thanks for the suggestion.

So if you don't mind, a bit more detail?

If in my .ascx "html" code I add something like: <input
onchange="javascript:
Changed( this );" type="file" ...
I can get the javascript function to fire but how can I update the
WebControl
and then get the page to redisplay? For example, in my UserControl class
(in
my .ascx.cs file) I have the following definition:

protected System.Web.UI.WebControls.TextBox Name;

We'll say I would like the javascript() to update this Name control and
then
"refresh" the page? It doesn't seem that I can do this, right? (note that
the
alert does work)

<script language="javascript">
function Changed( textControl )
{
alert( textControl.value );
Name.Text = textControl.value;
}
</script>

Thanks again for the help!

Larry

S. Justin Gengo wrote:
Larry,

You could attach a ontextchanged javascript to the input that would take
the
text in the input and add it to a list box.
Hi - I'm a newbie to .NET and I was hoping someone would be so kind as
to
help me out with a question?

[quoted text clipped - 17 lines]

Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1

Nov 19 '05 #4
Thanks again.

Sorry for asking again but given what you describe, my previous example
should update the Name field, right? But it's not. I've done this many times
before with .asp with not problems -- isn't this different because I'm using
runat="server"? How do I flush the changes to the Name control so they
visually appear??

Thanks.

Larry

S. Justin Gengo wrote:
Larry,

You'll need to look up a bit of javascript, but you can assign values to any
control on the page via javascript. So you could get the file path, add it
to a list box, and then delete the file path from the original input. I
wouldn't even worry about posting back until after your user has entered all
the files. Then give them a button to save the files that does the post back
after the list is complete.

To get you started here's the javascript to add an item to a listbox:

listbox.options[listbox.options.length] = new Option("Test", 15, false,
false);
Thanks for the suggestion.

[quoted text clipped - 41 lines]

Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1
Nov 19 '05 #5
Larry,

No problem! Don't worry, we'll get it.

Sorry, I wasn't clearer. I'm saying that I think you should do this all
client side. I would remove the runat=server from the input field altogether
and just use a javascript to move the contents of the input from the input
field to the list box. Then afte the user is done getting all the file names
they want to upload into the list box use a submit button, perhaps called
upload and below the list box, to do the post back.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Larry O via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:54***********@DotNetMonster.com...
Thanks again.

Sorry for asking again but given what you describe, my previous example
should update the Name field, right? But it's not. I've done this many
times
before with .asp with not problems -- isn't this different because I'm
using
runat="server"? How do I flush the changes to the Name control so they
visually appear??

Thanks.

Larry

S. Justin Gengo wrote:
Larry,

You'll need to look up a bit of javascript, but you can assign values to
any
control on the page via javascript. So you could get the file path, add it
to a list box, and then delete the file path from the original input. I
wouldn't even worry about posting back until after your user has entered
all
the files. Then give them a button to save the files that does the post
back
after the list is complete.

To get you started here's the javascript to add an item to a listbox:

listbox.options[listbox.options.length] = new Option("Test", 15, false,
false);
Thanks for the suggestion.

[quoted text clipped - 41 lines]
>
> Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1

Nov 19 '05 #6
Hi,

Well I got it to somewhat work but I believe I have a fundamental problem
mixing javascript with my <form> which is runat=server. This web application
is all runat=server and the page that I'm trying to integrate this change on
uses .NET features such as <asp:RegularExpressionValidator ...> So what
happens when my (javascript-written) data is visually on the page and a
Validator "refreshes" the page, the data is gone.

Here's my (non runat=server) code snippets...

First, I simply add the onchange():

<input onchange="javascript: Changed( this );" type="file" size="50"
id="FileToSend"
runat="server" NAME="FileToSend">

Then I just place a div tag where I want to display the Filename each time,
and an input field to house the data:

<div id="thediv"></div>
<input type=hidden id="thehidden">

Finally, the javascript:
<script language="javascript">
function Changed( theControl )
{
document.getElementById("thediv").innerHTML =
document.getElementById("thediv").innerHTML + "<br>" + theControl.
value;
}
</script>

Again, this is in an .ascx file where the <form> definition is 3 levels
removed. So when the user adds a few filenames, the list is visually
shown/updated properly on the page, but once a validator kicks in (e.g. <asp:
RequiredFieldValidator) all of the filenames previously shown on the page
goes away.

Is there a way to inplement this via .NET instead of using javascript or is
there a simple way to fix this?

Thanks much!

Larry

S. Justin Gengo wrote:
Larry,

No problem! Don't worry, we'll get it.

Sorry, I wasn't clearer. I'm saying that I think you should do this all
client side. I would remove the runat=server from the input field altogether
and just use a javascript to move the contents of the input from the input
field to the list box. Then afte the user is done getting all the file names
they want to upload into the list box use a submit button, perhaps called
upload and below the list box, to do the post back.
Thanks again.

[quoted text clipped - 32 lines]
>>
>> Larry

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #7
Larry,

Ok, I didn't know a post back was involved before the form is submitted. You
should go ahead and make your hidden input into a server side control. It
shouldn't affect your javascript. To do so declare an object with the same
name as your input like this:

Protected WithEvents FileToSend As
System.Web.UI.HtmlControls.HtmlInputHidden

When a postback occurrs get and then reset whatever is in the hidden input:

In your pageload sub:

Dim List As String = FileToSend.Value

FileToSend.Value = List
Or are you saying that the Validators are resetting the field when they run
clientside? (I don't think any fields should be lost unless a post back
occurrs...)

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Larry O via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:54***********@DotNetMonster.com...
Hi,

Well I got it to somewhat work but I believe I have a fundamental problem
mixing javascript with my <form> which is runat=server. This web
application
is all runat=server and the page that I'm trying to integrate this change
on
uses .NET features such as <asp:RegularExpressionValidator ...> So what
happens when my (javascript-written) data is visually on the page and a
Validator "refreshes" the page, the data is gone.

Here's my (non runat=server) code snippets...

First, I simply add the onchange():

<input onchange="javascript: Changed( this );" type="file" size="50"
id="FileToSend"
runat="server" NAME="FileToSend">

Then I just place a div tag where I want to display the Filename each
time,
and an input field to house the data:

<div id="thediv"></div>
<input type=hidden id="thehidden">

Finally, the javascript:
<script language="javascript">
function Changed( theControl )
{
document.getElementById("thediv").innerHTML =
document.getElementById("thediv").innerHTML + "<br>" +
theControl.
value;
}
</script>

Again, this is in an .ascx file where the <form> definition is 3 levels
removed. So when the user adds a few filenames, the list is visually
shown/updated properly on the page, but once a validator kicks in (e.g.
<asp:
RequiredFieldValidator) all of the filenames previously shown on the page
goes away.

Is there a way to inplement this via .NET instead of using javascript or
is
there a simple way to fix this?

Thanks much!

Larry

S. Justin Gengo wrote:
Larry,

No problem! Don't worry, we'll get it.

Sorry, I wasn't clearer. I'm saying that I think you should do this all
client side. I would remove the runat=server from the input field
altogether
and just use a javascript to move the contents of the input from the input
field to the list box. Then afte the user is done getting all the file
names
they want to upload into the list box use a submit button, perhaps called
upload and below the list box, to do the post back.
Thanks again.

[quoted text clipped - 32 lines]
>>>
>>> Larry

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #8
Hi,

I've fooled with this for many hours and unfortunately it's still not working.
Maybe a couple of pointed questions will help?

- If I have a hidden server control (runat=server) that I need to update from
within a Javascript script, is that possible? If so, would you be so kind as
to provide a simple working sample?

By the way, when Validators fire, they (apparently) do not alter server side
controls but do "clear" everything else.

Thanks.

Larry
S. Justin Gengo wrote:
Larry,

Ok, I didn't know a post back was involved before the form is submitted. You
should go ahead and make your hidden input into a server side control. It
shouldn't affect your javascript. To do so declare an object with the same
name as your input like this:

Protected WithEvents FileToSend As
System.Web.UI.HtmlControls.HtmlInputHidden

When a postback occurrs get and then reset whatever is in the hidden input:

In your pageload sub:

Dim List As String = FileToSend.Value

FileToSend.Value = List

Or are you saying that the Validators are resetting the field when they run
clientside? (I don't think any fields should be lost unless a post back
occurrs...)
Hi,

[quoted text clipped - 66 lines]
>>>>
>>>> Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1
Nov 19 '05 #9
Or might someone know how I could accomplish this without Javascript at all?
Basically how could I do the equavalent of capturing an onChange() event, but
call a .NET function instead of a JavaScript function??

Thanks!

Larry O wrote:
Hi,

I've fooled with this for many hours and unfortunately it's still not working.
Maybe a couple of pointed questions will help?

- If I have a hidden server control (runat=server) that I need to update from
within a Javascript script, is that possible? If so, would you be so kind as
to provide a simple working sample?

By the way, when Validators fire, they (apparently) do not alter server side
controls but do "clear" everything else.

Thanks.

Larry
Larry,

[quoted text clipped - 23 lines]
>>>>>
>>>>> Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1
Nov 19 '05 #10
Larry,

Here you go:

I did this pretty quickly, so it could use some cleanup, but I've verified
that everything works.

First the html for the design view:

<body>
<script language="javascript">
function addFile(fileName) {
textbox = document.getElementById('TextBox1');

if (textbox.value == '')
{
textbox.value = fileName;
}
else
{
textbox.value = textbox.value + '\n' + fileName;
}

}
</script>
<form id="frmLogin" runat="server">
<P><INPUT type="file" onchange="javascript:addFile(this.value);"></P>
<p>
<asp:TextBox id="TextBox1" runat="server" TextMode="MultiLine"
Height="68px" Width="352px" Wrap="False"
ReadOnly="True"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</p>
<P>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox2"></asp:RequiredFieldValidator></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>
</body>

And here's a button click event handler for the code behind to verify it
works:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Files() As String = TextBox1.Text.Split(Chr(13))

For Each FileName As String In Files
Response.Write(FileName & "<br>")
Next
End Sub
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Larry O via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:54***********@DotNetMonster.com...
Or might someone know how I could accomplish this without Javascript at
all?
Basically how could I do the equavalent of capturing an onChange() event,
but
call a .NET function instead of a JavaScript function??

Thanks!

Larry O wrote:
Hi,

I've fooled with this for many hours and unfortunately it's still not
working.
Maybe a couple of pointed questions will help?

- If I have a hidden server control (runat=server) that I need to update
from
within a Javascript script, is that possible? If so, would you be so kind
as
to provide a simple working sample?

By the way, when Validators fire, they (apparently) do not alter server
side
controls but do "clear" everything else.

Thanks.

Larry
Larry,

[quoted text clipped - 23 lines]
>>>>>>
>>>>>> Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1

Nov 19 '05 #11
Larry,

Change the form tag back to Form1.

I just noticed that it wasn't. I used a "Lab" project I fool around with all
the time when answering people's questions and I must have changed the
form's name at some point and not changed it back.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:OG**************@TK2MSFTNGP10.phx.gbl...
Larry,

Here you go:

I did this pretty quickly, so it could use some cleanup, but I've verified
that everything works.

First the html for the design view:

<body>
<script language="javascript">
function addFile(fileName) {
textbox = document.getElementById('TextBox1');

if (textbox.value == '')
{
textbox.value = fileName;
}
else
{
textbox.value = textbox.value + '\n' + fileName;
}

}
</script>
<form id="frmLogin" runat="server">
<P><INPUT type="file" onchange="javascript:addFile(this.value);"></P>
<p>
<asp:TextBox id="TextBox1" runat="server" TextMode="MultiLine"
Height="68px" Width="352px" Wrap="False"
ReadOnly="True"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</p>
<P>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox2"></asp:RequiredFieldValidator></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>
</body>

And here's a button click event handler for the code behind to verify it
works:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Files() As String = TextBox1.Text.Split(Chr(13))

For Each FileName As String In Files
Response.Write(FileName & "<br>")
Next
End Sub
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Larry O via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:54***********@DotNetMonster.com...
Or might someone know how I could accomplish this without Javascript at
all?
Basically how could I do the equavalent of capturing an onChange() event,
but
call a .NET function instead of a JavaScript function??

Thanks!

Larry O wrote:
Hi,

I've fooled with this for many hours and unfortunately it's still not
working.
Maybe a couple of pointed questions will help?

- If I have a hidden server control (runat=server) that I need to update
from
within a Javascript script, is that possible? If so, would you be so kind
as
to provide a simple working sample?

By the way, when Validators fire, they (apparently) do not alter server
side
controls but do "clear" everything else.

Thanks.

Larry

Larry,

[quoted text clipped - 23 lines]
>>>>>>>
>>>>>>> Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1


Nov 19 '05 #12
Thanks! Will take a look at this...

S. Justin Gengo wrote:
Larry,

Change the form tag back to Form1.

I just noticed that it wasn't. I used a "Lab" project I fool around with all
the time when answering people's questions and I must have changed the
form's name at some point and not changed it back.
Larry,

[quoted text clipped - 86 lines]
>>>>>>>>
>>>>>>>> Larry

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200509/1
Nov 19 '05 #13
Sorry but I decided to take a more simple approach with this problem. I
simply put eight controls on the page so the user can decide to fill in as
many or few files as they desire. It seems to be more obvious what they are
specifying and easier to pull out the data on the other end.

Thanks so much for all the help on this!

Larry

Larry O wrote:
Thanks! Will take a look at this...
Larry,

[quoted text clipped - 9 lines]
>>>>>>>>>
>>>>>>>>> Larry

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #14

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

Similar topics

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...
1
by: Brad | last post by:
The following code work on my pc (win2003 server) but does not work when deployed to a server (win2000 server). For count As Integer = 1 To 4 Dim input As New HtmlInputFile input =...
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: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
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...
2
by: Sean Carey | last post by:
I converted a C# Upload app to VB.NET and am down to one error and was hoping someone could help me with te error. I would greatly appreciate help from anyone. Here is the error: ...
2
by: PawelR | last post by:
Hello, I have question about HtmlInputFile. How change caption in HtmlInputFile from "Browse ..." to other? THX PawelR
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
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.