?
Solved

HtmlInputFile OnClick Event

Posted on 2006-05-11
6
Medium Priority
?
559 Views
Last Modified: 2012-05-05
Is there any way to hook an HtmlInputFile control's user events?
For instance, when a user click's "Browse" or when the value
is populated?

It is easy to do with Javascript, but I need the event to trigger
some server side code.

I am using C#, but VB examples are fine.
--brian
0
Comment
Question by:Brian Bush
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 16661665
I think the only way you could do it is have Javascript submit the form when the "OnClick" event of the Browse button takes place.
0
 
LVL 2

Expert Comment

by:koolkraft
ID: 16661778
Hi,

This is how you add the postback javascript to your page. you can use that in javascript functions etc. as well.

<input type=file ID=fileUpload runat=server onclick='<%= Page.GetPostBackEventReference(new PostBackOptions(this.fileUpload),null,true) %>' />
0
 
LVL 6

Author Comment

by:Brian Bush
ID: 16662019
I am liking the GetPostBackEventReference, but I don't quite understand how to make use of it.
Can you elaborate a little more?

--brian
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
koolkraft earned 2000 total points
ID: 16662313
What i gave you is not completely right i'm sorry for that because I  don't know with which version of asp.net you're working. I'll continue my explanation assuming that it is .net 2.0

you should access all clientscripting features through the Page.ClientScript API

What the GetPostBackEventReference method does is bascally provide your html control with a small piece of javascript that allows your control to post the page back to the server

This is the msdn page that deals with it.
http://msdn2.microsoft.com/en-US/library/ms153112.aspx

I wanted to give you a small example but it would be almost the same as what 's on the page of msdn. Take a look there that should help you a bit further

What's also worth taking a look at would be the callback feature
http://msdn2.microsoft.com/en-US/library/ms178208.aspx
0
 
LVL 6

Author Comment

by:Brian Bush
ID: 16668656
I am using Visual Studio 2003 which apparently means
I don't even have the option to use .NET 2.0.
This has given me some good ideas though.

--brian
0
 
LVL 2

Expert Comment

by:koolkraft
ID: 16670774
doesn't matter so much in asp.net 1.1 you don't have to access it through the Page.ClientScript API but it are methods that belong to any control

then it would go Page.GetPostBackEventReference

For the rest there shouldn't be such a big difference. it's still asp.net wether it's 1.1 or 2.0
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question