Avoid adding a new record on refreshing the browser

S

srinivas

Hi,

I'm working with datagrid. And users can add "Remarks" by clicking the [Add]
link button in the footer template.

It's working fine like when the user enter the remarks and click on [Add],
the remarks are getting added.

But if we refresh the page, a new record is getting added, which should not
happen

I do not have any unique columns (other than Remark Id) in the table sine we
can add the remarks any number of times.

Any suggestion in this regards is highly appreciated.

srinivas
 
E

Eliyahu Goldin

That's built-in behavior of Refresh button. It always repeats the last
postback. You can't change it. You can protect against it on server side if
you include something like a timestamp in the postback. Then you can compare
the timestamp from the new postback with the one from the previous postback.
If they match, you got Refresh click.

Eliyahu
 
M

MA

I´m not sure aboute this, but can´t you use if(!Page.IsPostback) ?

/Marre

Eliyahu Goldin said:
That's built-in behavior of Refresh button. It always repeats the last
postback. You can't change it. You can protect against it on server side
if
you include something like a timestamp in the postback. Then you can
compare
the timestamp from the new postback with the one from the previous
postback.
If they match, you got Refresh click.

Eliyahu

srinivas said:
Hi,

I'm working with datagrid. And users can add "Remarks" by clicking the [Add]
link button in the footer template.

It's working fine like when the user enter the remarks and click on
[Add],
the remarks are getting added.

But if we refresh the page, a new record is getting added, which should not
happen

I do not have any unique columns (other than Remark Id) in the table sine we
can add the remarks any number of times.

Any suggestion in this regards is highly appreciated.

srinivas
 
E

Eliyahu Goldin

Marre,

Page.IsPostback will always return true after pressing Refresh for the
simple reason it IS a postback.

Eliyahu

MA said:
I´m not sure aboute this, but can´t you use if(!Page.IsPostback) ?

/Marre

Eliyahu Goldin said:
That's built-in behavior of Refresh button. It always repeats the last
postback. You can't change it. You can protect against it on server side
if
you include something like a timestamp in the postback. Then you can
compare
the timestamp from the new postback with the one from the previous
postback.
If they match, you got Refresh click.

Eliyahu

srinivas said:
Hi,

I'm working with datagrid. And users can add "Remarks" by clicking the [Add]
link button in the footer template.

It's working fine like when the user enter the remarks and click on
[Add],
the remarks are getting added.

But if we refresh the page, a new record is getting added, which should not
happen

I do not have any unique columns (other than Remark Id) in the table
sine
we
can add the remarks any number of times.

Any suggestion in this regards is highly appreciated.

srinivas
 
M

MA

Hi Eliyahu!

Yes it will. Thats why i used !Page.IsPostback. Should´nt that solve the
problem with F5?

F5 is allways a postback. If you use:
if(!Page.IsPostback)
{
code.....
}
the code inside my if-block would not be used when F5 is pressed.

Is something I miss here, or could this work? :)

/Marre

Eliyahu Goldin said:
Marre,

Page.IsPostback will always return true after pressing Refresh for the
simple reason it IS a postback.

Eliyahu

MA said:
I´m not sure aboute this, but can´t you use if(!Page.IsPostback) ?

/Marre

Eliyahu Goldin said:
That's built-in behavior of Refresh button. It always repeats the last
postback. You can't change it. You can protect against it on server
side
if
you include something like a timestamp in the postback. Then you can
compare
the timestamp from the new postback with the one from the previous
postback.
If they match, you got Refresh click.

Eliyahu

Hi,

I'm working with datagrid. And users can add "Remarks" by clicking the
[Add]
link button in the footer template.

It's working fine like when the user enter the remarks and click on
[Add],
the remarks are getting added.

But if we refresh the page, a new record is getting added, which
should
not
happen

I do not have any unique columns (other than Remark Id) in the table sine
we
can add the remarks any number of times.

Any suggestion in this regards is highly appreciated.

srinivas
 
E

Eliyahu Goldin

Marre,

The question is how you differentiate between a real postback caused, for
example, by a form button click, and a postback caused by F5. If you use
if(!Page.IsPostback), you are going to miss all your real postbacks.

What you are suggesting is good in a case when you don't have any real
postbacks, for example you are producing a view-only form.

Eliyahu

MA said:
Hi Eliyahu!

Yes it will. Thats why i used !Page.IsPostback. Should´nt that solve the
problem with F5?

F5 is allways a postback. If you use:
if(!Page.IsPostback)
{
code.....
}
the code inside my if-block would not be used when F5 is pressed.

Is something I miss here, or could this work? :)

/Marre

Eliyahu Goldin said:
Marre,

Page.IsPostback will always return true after pressing Refresh for the
simple reason it IS a postback.

Eliyahu

MA said:
I´m not sure aboute this, but can´t you use if(!Page.IsPostback) ?

/Marre

That's built-in behavior of Refresh button. It always repeats the last
postback. You can't change it. You can protect against it on server
side
if
you include something like a timestamp in the postback. Then you can
compare
the timestamp from the new postback with the one from the previous
postback.
If they match, you got Refresh click.

Eliyahu

Hi,

I'm working with datagrid. And users can add "Remarks" by clicking the
[Add]
link button in the footer template.

It's working fine like when the user enter the remarks and click on
[Add],
the remarks are getting added.

But if we refresh the page, a new record is getting added, which
should
not
happen

I do not have any unique columns (other than Remark Id) in the table sine
we
can add the remarks any number of times.

Any suggestion in this regards is highly appreciated.

srinivas
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top