开发者

What is the life cycle of an ASP.NET file upload on code behind?

I would like to know what events get executed (if any) after a user has selected to submit a file for upload on an ASP.NET page.

Would I need to tweak anything at the IIS level?

Should the page life cycle events be triggered when the user uploads a file?

I see different behaviour on my 开发者_如何学JAVAdevelopment server from Visual Studio in regards to the IIS server I deploy to:

on the development server, the life cycle events get triggered when a file gets selected, on the deployed server they don't..

What classes would I need to override, what web.config settings should I change, in order to tweak the default behaviour of the upload?

The problem I am having, is finding documentation on how to have code executed before the file gets uploaded, but after a file got selected.

P.S. this is related to a previous question of mine here, but approached in a very different way in the hopes of understanding the whole upload process, so I thought it's a different question all together.


No, it has no event for file upload(maybe on .net 4)

what I did was a class that derives from the upload object and on OnLoad event something like this:

public event EventHandler OnUpload;
protected void OnLoad(...){
   if (this.HasFile && this.OnUpload != null)
     this.OnUpload(this, EventArgs.Empty);
}

sort of that.

Joe

-- Edit: Oh, I re-read your post and you want to know when people selects a file but it is not yet sent to the server? thats javascript. Server side can't know when people select it without sending a information to the server. You can develop a WebService function that is called when the onchanged of the input has been called, but I don't know if thats a good idea. Can you use javascript for this?

try:

  <asp:textbox id="t1" runat="server"/>

on code behind:

  t1.Attributes.Add("onchange", "alert('it changed its value: ' + this.value);");

hope it helps.


To execute code before upload, it would have to be JavaSript code running in the browser. See my answer to a question about filtering file uploads based on type:

How to filter which files can be seen on upload dialog box?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜