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

Preventing double post by refreshing?

How can I prevent a second (or third or fourth) post into a database by
someone clicking the refresh button on their browser?

Basically, the user clicks a button called "New Log", which makes most
of the form within a <div runat="server"to go invisible and another
<divgo visible. This includes a text box and a save button. They type
text into the textbox and click save, which executes a stored procedure
that does the insert into an SQL database. Then that <divgoes
invisible and the original <divgoes visible. This all works fine but
if they hit the refresh button, another, exact post is supplied (with a
new time stamp since I also insert Now().

I tried this:

If txtNewLog.Text = "" Then

Else
objConnection.Open()
strNameUsers = objCommandUsers.ExecuteScalar()
objName.Value = strNameUsers
objCommand.ExecuteNonQuery()
objConnection.Close()

txtNewLog.Text = vbNullString
divPost.Visible = False
PopulateList("")
divNotes.Visible = True
txtNewLog.Text = ""
End If

Note that I try to clear the contents of the text box after the insert
is complete. I was hoping that if they hit refresh, the insert wouldn't
take place with this coding, but it does.

TIA,
Jim
Jan 9 '07 #1
3 2313
Milosz Skalecki [MCAD] wrote:
Hi Jim,

You can implement IsRefersh property, but you need both viewstate and
session to be enabled, C# example:
Since I've never had to deal with turning on or off the viewstate or
session, I dont' know how to do that. I'll look into it.

I definitely don't know c sharp but I'm sure I can make out your code
with a little focus and head scratching. ;)

Thanks for your response. I didn't know there was a 'IsRefresh' until
now so, armed with that, I'll give it a go.
Jan 9 '07 #2
Jim in Arizona wrote:
Milosz Skalecki [MCAD] wrote:
>Hi Jim,

You can implement IsRefersh property, but you need both viewstate and
session to be enabled, C# example:

Since I've never had to deal with turning on or off the viewstate or
session, I dont' know how to do that. I'll look into it.

I definitely don't know c sharp but I'm sure I can make out your code
with a little focus and head scratching. ;)

Thanks for your response. I didn't know there was a 'IsRefresh' until
now so, armed with that, I'll give it a go.
This code converter worked, apparently.

http://www.developerfusion.co.uk/uti...sharptovb.aspx

With this result:

Private Const refLockCountFieldName As String = "__refLockCount"

Protected Overloads Overrides Sub Render(ByVal output As HtmlTextWriter)
Page.RegisterHiddenField(refLockCountFieldName,
SessionLockUpdateCount.ToString)
MyBase.Render(output)
End Sub
Private isRefreshLock As Boolean = False
Private Const initialLockUpdateValue As Integer = 1

Private Sub EnsureRefreshLock()
If isRefreshLock Then
Return
End If
If Not IsPostBack Then
SessionLockUpdateCount = initialLockUpdateValue
End If
Dim count As Integer = HdnLockUpdateCount + 1
If count SessionLockUpdateCount Then
SessionLockUpdateCount = count
Else
isRefresh = True
End If
isRefreshLock = True
End Sub
Private isRefresh As Boolean = False

Public ReadOnly Property IsRefresh() As Boolean
Get
EnsureRefreshLock
Return isRefresh
End Get
End Property

Protected ReadOnly Property HdnLockUpdateCount() As Integer
Get
Dim str As String = Request(refLockCountFieldName)
Dim count As Integer = initialLockUpdateValue
If Not (str Is Nothing) AndAlso str.Length 0 Then
Try
count = Int32.Parse(str)
Catch
End Try
End If
Return count
End Get
End Property

Protected Property SessionLockUpdateCount() As Integer
Get
Dim obj As Object = Session("LockUpdate")
Return Microsoft.VisualBasic.IIf(obj Is
Nothing,initialLockUpdateValue,CType(obj, Integer))
End Get
Set
Session("LockUpdate") = value
End Set
End Property
Jan 9 '07 #3
Milosz Skalecki [MCAD] wrote:
Hi again,

Both session and viewstate are enabled by default, i mentioned this, in case
you might have set page's viewstate to false or turned session state off.
Sorry i posted c# version but i didn't have time to translate it to vb.net
(you'll be fine :)

hope this helps
I couldn't get that code to work after I tried converting it. I did find
this article:

http://aspalliance.com/687

It happens to be in VB too, which was great for me. I found that, in my
case, all I had to do was use this within my button sub:

Response.Redirect(Request.Url.ToString(), false)

That works fine since maintaining viewstate isn't necessary on that page.

Thanks,
Jim
Jan 16 '07 #4

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

Similar topics

7
by: Matt | last post by:
I have an interactive web page that I need to prevent refreshes on. The problem is that I want to ALLOW resubmissions, but only via the submit button. My web page has two forms on it, one form for...
3
by: Troy | last post by:
Hello- I have a website that uses a custom built webserver to serve the pages. (Please don't ask me why my boss had his own web server written). I am displaying a log of information that is an...
2
by: Obi Wan Shinobi | last post by:
I can't seem to prevent the refresh associated with F5 in Netscape. I can capture the key but returning false does not prevent the refresh. The code is as follows: function keyDown(e) { if...
6
by: Rey | last post by:
Howdy all. Am attempting to delete a large number of records (123K) from a table using: db.execute "delete from tblname" Then I double check (code below) to see if records still remain as...
6
by: Mark | last post by:
i'm using an html form to submit comments to a database. the form is on the same page where the comments are being displayed. if you hit submit, your comment appears as it should, but then if you...
13
by: Oleg Konovalov | last post by:
Hi, I have a Java GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and clicks...
8
by: ninuhadida | last post by:
hi there! This is actually my first post over here.. I thought i'd register since most answers to my common problems that i google up turn up to be in this site.. however I have a problem myself now....
9
by: Ned White | last post by:
Hi All, Im my c# web project, users click a submit button for credit card payment process. On the web server side ( on ButtonClick_Event) the user's input(name,date,cc number etc.) is processed...
2
by: chrisp | last post by:
I have an ASP.NET 2 page with a button that causes a credit card transaction to be authorised. The authorisation procedure may take a few seconds and so I want to prevent the user from clicking the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.