473,388 Members | 1,600 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,388 software developers and data experts.

File upload control issues with ASP.NET 1.1 (playing with fire)

Heya all,

I'm working on a web-based application (using ASP.NET and C# on .NET
1.1.4322, supporting only IE6 for Windows) that allows for file uploads.
Screen real estate is at a premium, so I want to set its style to "display:
none;" and interact only with the standard file upload dialog (which can be
summoned by firing the click() method of the control).

Attempting programmatic access of a file upload control is generally playing
with fire, and this time is apparently no exception. Once I call the
click() method, it seems, the page is no longer able to post back. When I
attempt to submit the form, the value of the file upload control is cleared
and the page just sits there; no network traffic is generated as a result of
the attempted form submission. However, if I make the file upload control
visible and manually click its "Browse..." button, the page posts back
correctly.

For those of you familiar with Gmail's attachment upload interface, this is
very close to the effect I am trying to achieve, but something about ASP.NET
is apparently interfering (probably for my own protection) with the process.
Has anybody experienced similar behavior under the same platform, and if so,
explain the behavior or point to a KB article or security documentation that
might be enlightening ?

Thanks greatly for your time. Toy code follows.

R. Jones
ra*********@gmail.com

Codeahead:
==========

<%@ Page language="c#" Codebehind="Foo.aspx.cs" AutoEventWireup="false"
Inherits="FooApp.Foo" %>

<script>

function foo()
{
document.getElementById('<% = this.f.ClientID %>').click();
}

</script>

<body>
<form runat="server" id="form1" enctype="multipart/form-data">

<!-- just here to make it easier to tell when a roundtrip has occurred -->
<div id="b"></div>

<input runat="server" type="file" id="f">

<input type="submit" value="Submit">

<!-- programmatically summon file upload dialog -->
<input type="button" onclick="foo();" value="Upload file
programmatically...">

<!-- button to avoid "page has expired" message -->
<input type="button" onclick="window.location.href =
'http://localhost/Foo.aspx';" value="Clear">

<br>

Postback info:
<div runat="server" id="s" /> <!-- info provided on postback -->

</form>
</body>

<script>

document.getElementById('b').innerText = new Date().toString();

</script>

Codebehind:
===========

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace FooApp
{
public class Foo : System.Web.UI.Page
{
protected HtmlInputFile f;
protected HtmlGenericControl s;

private void Page_Load(object sender, System.EventArgs e)
{
if (this.IsPostBack)
{
s.InnerText = String.Format("{0} file(s) posted", Request.Files.Count);
if (1 == Request.Files.Count) { s.InnerText += String.Format(", content
length: {0}", Request.Files[0].ContentLength); }
}
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}
Jan 3 '06 #1
0 2446

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

Similar topics

1
by: Jonatan | last post by:
Hi all, I'm trying to upload files doing something like gmail. I almost got it but I have a problem when I post the form. Basicaly, I am doing the following. When the user presses the link...
2
by: Anne | last post by:
hie all, i have dragged a File Field control from the HTML tab to my page and i am able to browse and retrieve the file i want. the only problem i have is, i do not want my users to be able to...
1
by: Stefan Berger | last post by:
Hello everybody, i have a proble with uploading files in asp.net. i want to make a special file upload-page without displaying the common html-file-upload-control. i have a made an additional...
4
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users...
0
by: Webmills | last post by:
Hi I have a form containing a File Upload Control, Required Field Validator (connected to the file upload control) RegularExpressionValidator (connected to the file upload control,...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
3
by: c676228 | last post by:
Hi everyone, I will develop a program to enroll a group of people on-line. Since we don't have number limitation for the people in the group. I am wondering if there is any company allow people...
2
by: Mike Kober | last post by:
I am having issues with the File Upload control for sending files to the server via HTTP. The speed of the upload is often between 20kbs and 40kbs. If I use the LAN at work to the server, it...
3
by: bsm | last post by:
Hi, I have File Upload control in my form. When I click Enter key, it triggers "Submit" button event. So I wrote onkeydown function as follows: if (window.event.keycode == 13) { return...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.