GridView and delete problems with page refresh

J

J055

Hi

I have a GridView which includes the ability to delete rows. This works fine
accept for when a naughty user decides to refresh the browser thereby
posting the same delete command instruction. The problem with this is that
the refresh will either delete another record or generate an exception,
something like this:

An error has occurred because a control with id
'ctl00$Main$UserGrid$ctl11$ctl00' could not be located

The first scenario is unwelcome but the second is very nasty because it's
then very difficult for the user to remedy the situation. It's easy to see
why this is happening because the post data for the delete command contains
the index of the row and then matches it to a CommandArgument held in the
viewstate (I think). In my case the CommandArgument contains the PrimaryKey
ID of the record being deleted so when I refresh the page I am deleting the
record which takes the previous record's place, if one exists, else I get
the above error.

Is there a way to handle this better? How do I make this more robust? What
is actually happening in the page life cycle and the viewstate when I delete
a record?

In the old days you would sent the record ID with the get/post request. Why
can't we make the GridView do this?

Cheers
Andrew
 
W

Walter Wang [MSFT]

Hi Andrew,

Thank you for your post!

You can take a look at following article to see a possible solution:

#Build Your ASP.NET Pages on a Richer Bedrock
http://msdn.microsoft.com/asp.net/community/authors/dinoesposito/default.asp
x?pull=/library/en-us/dnvs05/html/bedrockaspnet.asp

It uses a custom HTTP module to intercept the HttpApplication's
AcquireRequestState event and checks if this is a duplicated POSTBACK
caused by Refresh.

Please feel free to post here if you need more help.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top