473,406 Members | 2,259 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.

How do I handle two HTMLFileInput controls on one page?

Hello,

I am writing a page that allows the user to upload two images to the
server. I have two HTMLInputFile controls on the page ...

<input id="smallimage" Type="File" Runat="Server">
<br><input id="largeimage" Type="File" Runat="Server">

and the code that handle the postback looks like this...

if ((smallimage.PostedFile != null) && (smallimage.PostedFile.ContentLength > 0)) {
try {
smallimage.PostedFile.SaveAs(imagePath + "small.jpg");
} catch (Exception ex) {
// display an error message
}
}
if ((largeimage.PostedFile != null) && (largeimage.PostedFile.ContentLength > 0)) {
try {
largeimage.PostedFile.SaveAs(imagePath + "large.jpg");
} catch (Exception ex) {
// display an error message
}
}

Now, if I choose just a small image, then it gets saved twice, once as
"small.jpg" and once as "large.jpg". If I choose both images, then the
small one gets saved twice (ie the large one is ignored). If I only
choose the large image, then it saves something that isn't an image.
Presumably this is the non-existent small image.

I'm sure I'm making some basic mistake here. Please could someone show
me how to handle two file controls on one page.

Thanks in advance.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
2 1221
On Thu, 16 Jun 2005 18:55:57 +0100, Alan Silver wrote:
Hello,

I am writing a page that allows the user to upload two images to the
server. I have two HTMLInputFile controls on the page ...

<input id="smallimage" Type="File" Runat="Server">
<br><input id="largeimage" Type="File" Runat="Server">

and the code that handle the postback looks like this...

if ((smallimage.PostedFile != null) && (smallimage.PostedFile.ContentLength > 0)) {
try {
smallimage.PostedFile.SaveAs(imagePath + "small.jpg");
} catch (Exception ex) {
// display an error message
}
}
if ((largeimage.PostedFile != null) && (largeimage.PostedFile.ContentLength > 0)) {
try {
largeimage.PostedFile.SaveAs(imagePath + "large.jpg");
} catch (Exception ex) {
// display an error message
}
}

Now, if I choose just a small image, then it gets saved twice, once as
"small.jpg" and once as "large.jpg". If I choose both images, then the
small one gets saved twice (ie the large one is ignored). If I only
choose the large image, then it saves something that isn't an image.
Presumably this is the non-existent small image.

I'm sure I'm making some basic mistake here. Please could someone show
me how to handle two file controls on one page.

Thanks in advance.

Basically you are making the mistake to assume that web programming is the
the same as forms programming. When you 'choose' one or both of the images
nothing in particular should happen at the server. However, when the web
form is posted your server code is looking at what gets posted back and
the order of the ifs tell the story.

Nov 19 '05 #2
>Basically you are making the mistake to assume that web programming is the
the same as forms programming. When you 'choose' one or both of the images
nothing in particular should happen at the server. However, when the web
form is posted your server code is looking at what gets posted back and
the order of the ifs tell the story.


Sorry, I don't understand what you mean. The code I showed is executed
on the server when the page is posted back. I was under the impression
that each server control was a separate object in the code.

Therefore, as I have two file input controls, I expected to have two
separate objects in the code. The order of the ifs should be irrelevant
here as each should be independent.

Please could you clarify what you mean and maybe post some code to
explain how you are supposed to handle two file input controls.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #3

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

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
4
by: Roberto López | last post by:
Hello, I´m trying to do a progress page that indicates some visual information to the user in a long directory copy process. I have a Class that copys directories from one location to other. The...
2
by: Michael Ramey | last post by:
Howdy, I think I have a good question! I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which...
3
by: FayHuang | last post by:
Hi, I am very new beginner to ASP.NET, but I inherited this ASP.NET project from a person who left our company. So I hope that my problem is fairly simple to solve. Here is the background to...
0
by: 234 | last post by:
I have a button for which I want to handle the click event. Here is my setup: The base page, simplified for discussion: ================================= Public Class clsBasePage Inherits...
6
by: Andrew | last post by:
Hello, friends, I tried to do cross-page posting, i.e., in firstpage.aspx I used action="secondpage.aspx". Since I am using asp.net 1.1, so it always goes back to firstpage.aspx aftern...
3
by: Learner | last post by:
Hello there, I have built as .aspx page. I have a situation to create 4 panels in a <td></td. Based on the selection of a drop down I need to display the corresponding panel in that table cell....
1
by: Benny Ng | last post by:
Dear All, Now I met one problem in the development of my one application. I have one ASP.NET page. It's for disply the information of customer. But now I have one new requirement. It's to...
0
by: aparnaa | last post by:
hi i am developing a web page in asp.net(VB) here i have dynamicaaly created a button. i have created this button in a procedure so that i can call it at varied places. however, i am not able to...
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
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
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...
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
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
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.