refresh button /// or /// reload of page

a8le

Well-known member
Joined
Oct 27, 2005
Messages
75
Programming Experience
5-10
hi all,

i have a procedure that adds unique rows into a sql server table...

my problem is after hitting the button, the data is entered without any problems, but if i then hit the refresh button (F5), the same (but unique... increment of 1 on ID) data is entered again, giving me a second row.

things i have tried:

1) cleared out the form data, for example,
VB.NET:
lastName.text = ""

but that didn't work

2) checked to ensure that the data is not already there, for example,
VB.NET:
if lastName(param).Count > 0 then... 
don't do add procedure
else
do add procedure
end if

but that didn't work

3) tried to see if it was a postback problem, for example
VB.NET:
if not page.ispostback then....

but that didn't work...

I just can't figure it out, please help... i would appreciate any help. thanx in advance.

-a8le
 
when you hit the F5 button/cause a refresh, this repeats the last action that was performed to get you to the page you are looking at... for example, if one one page you hit a button and the results are then displayed, if the user hits refresh, the web page is basically acting like they hit the button again. My reco would be to go back to the button/object that called the postback and put a if statement around it's method.

I have found that for dynamically generated pages you can not always count on the page.ispostback logic to determine when things need to be drawn/redrawn... so I would add a boolean property to your page/control called RenderComplete defaulting to false. When the page first loads it will be false so the page should render, but after the page renders set the property to true (make sure the RenderComplete property is stored in ViewState)... example:
VB.NET:
Private Property RenderComplete() as Boolean
   Get
      Return CBool(ViewState("RenderComplete"))
   End Get
   Set (value as Boolean)
      ViewState("RenderComplete") = value
   End Set
End Property

THen you can wrap your drawing methods w/ If Not RenderComplete Then DrawPage() End If ... or something like that.
 
m_ogden,

i tried what you suggestted but it didn't work... its probably because i tied the rendercomplete = false/true to postback.

how do you suggest when to set rendercomplete true or false?

-a8le
 
Set the RenderComplete = true at the end of your method which adds the data to the data table... for example, in your original posting the second code block could be changed to:
VB.NET:
if RenderComplete then
   'don't do add procedure
else
   'do add procedure
   RenderComplete = True
end if
 
m_ogden,

oddly enough... i tried something like that, but it didn't work. I think its is because i didn't tied the value to viewstate.

however with the logic you presented, i went ahead and edited my stored procedure to do a check before inserting another row/record.

everything works as it should now, thank you for all the help!

sincerely,
a8le
 
Back
Top