Saturday, March 31, 2012

What is probably a simple question about a file control

I'm rather new to ASP .Net, so I appologize in advance if I'm asking a dumb
question here. I've been searching all over the place for an answer and
haven't found a single one.

I'm working on a form that gives the user a file control to upload a file
from their machine to my server. With this file control are two buttons; one
marked "Upload", the other marked "Cancel". The cancel button is to give
them the option of just backing out entirely. Upon clicking the Cancel
button, the C# code redirects them to the previous page.

The problem I'm having is that if the user has already selected a file on
their computer (through clicking Browse, etc.) and they click "Cancel" the
file is uploaded to the server anyway. How do I prevent the upload if they
click the "Cancel" button and not the "Upload" button.

Thanks in advance,
edif the only functionality of cancel is to go back to last page , change
cancel button to an HTML button.. it doesnt need to post back the page.

<input type=button onclick='javascript:history.back(-1);' value='Cancel'
Still how is it uploading file on cancel button?.. :) Is your c# code to
save the file on in the btnUpload_Click(Sender as Object, e as EventArgs)
[btnUpload being name of your uplaod control] or in the Page_Load ?

btnUpload_Click(Sender as Object, e as EventArgs) is the currect place for
saving the file to server..

"Ed" wrote:

> I'm rather new to ASP .Net, so I appologize in advance if I'm asking a dumb
> question here. I've been searching all over the place for an answer and
> haven't found a single one.
> I'm working on a form that gives the user a file control to upload a file
> from their machine to my server. With this file control are two buttons; one
> marked "Upload", the other marked "Cancel". The cancel button is to give
> them the option of just backing out entirely. Upon clicking the Cancel
> button, the C# code redirects them to the previous page.
> The problem I'm having is that if the user has already selected a file on
> their computer (through clicking Browse, etc.) and they click "Cancel" the
> file is uploaded to the server anyway. How do I prevent the upload if they
> click the "Cancel" button and not the "Upload" button.
> Thanks in advance,
> ed
Sreejith,
thanks. Thats exactly what I was looking for.

ed

"Sreejith Ram" wrote:

> if the only functionality of cancel is to go back to last page , change
> cancel button to an HTML button.. it doesnt need to post back the page.
> <input type=button onclick='javascript:history.back(-1);' value='Cancel'>
> Still how is it uploading file on cancel button?.. :) Is your c# code to
> save the file on in the btnUpload_Click(Sender as Object, e as EventArgs)
> [btnUpload being name of your uplaod control] or in the Page_Load ?
> btnUpload_Click(Sender as Object, e as EventArgs) is the currect place for
> saving the file to server..
>
> "Ed" wrote:
> > I'm rather new to ASP .Net, so I appologize in advance if I'm asking a dumb
> > question here. I've been searching all over the place for an answer and
> > haven't found a single one.
> > I'm working on a form that gives the user a file control to upload a file
> > from their machine to my server. With this file control are two buttons; one
> > marked "Upload", the other marked "Cancel". The cancel button is to give
> > them the option of just backing out entirely. Upon clicking the Cancel
> > button, the C# code redirects them to the previous page.
> > The problem I'm having is that if the user has already selected a file on
> > their computer (through clicking Browse, etc.) and they click "Cancel" the
> > file is uploaded to the server anyway. How do I prevent the upload if they
> > click the "Cancel" button and not the "Upload" button.
> > Thanks in advance,
> > ed

0 comments:

Post a Comment