How to detect users refresh in my asp.net page

J

Jack Li

You may keep a counter session variable and increase that per each request.
A copy of this value is also stored on the client side (for example on the
query string). If the request is being sent multiple times by hitting the
browser refresh button, you can detect it on the server side by comparing
the counter.

Regards,
Jack Li
MVP (ASP.NET)
 
J

J-T

I have a form :

<form id="frmUpload" name="UploadFileFromClientForm" method="post"
encType="multipart/form-data" runat="server">
......

<INPUT id="UploadTheFile" type="button" value="Upload" name="UploadTheFile"
runat="server">
.......
</form>

and here is the code behind it:
private void UploadTheFile_ServerClick(object sender, System.EventArgs e)

{

HttpPostedFile file = File1.PostedFile;

byte[] fileData = new byte[file.ContentLength];

file.InputStream.Read(fileData, 0, file.ContentLength);

uploader.FileName=Path.GetFileName(file.FileName);

uploader.Upload();


}

whenever the user refreshes the page UploadTheFile_ServerClick is being
called and another record with the same information is being inserted into
my database.



Any,suggestions?



Thanks
 
J

Joerg Jooss

J-T said:
I have a form :

<form id="frmUpload" name="UploadFileFromClientForm" method="post"
encType="multipart/form-data" runat="server"> .....

<INPUT id="UploadTheFile" type="button" value="Upload"
name="UploadTheFile" runat="server"> ......
</form>

and here is the code behind it:
private void UploadTheFile_ServerClick(object sender,
System.EventArgs e)

{

HttpPostedFile file = File1.PostedFile;

byte[] fileData = new byte[file.ContentLength];

file.InputStream.Read(fileData, 0, file.ContentLength);

uploader.FileName=Path.GetFileName(file.FileName);

uploader.Upload();


}

whenever the user refreshes the page UploadTheFile_ServerClick is
being called and another record with the same information is being
inserted into my database.



Any,suggestions?

A synchronizer token will help. Here's an article with a sample
implementation: http://tinyurl.com/3ma4x

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top