Thursday, May 15, 2014

RadGrid duplicate insert after page refresh

Hi guys,

Here's a quick one. I had a problem with a RadGrid I created for an application page the other day. It's a common known problem in the ASP.NET community and I saw several solutions but there is a very simple one to it. Let me explain the issue first. Whenever I would insert/update/delete a record using the grid and I would refresh the page, the application would fire that event again. This could potentially cause duplicate inserts or exceptions being thrown whenever trying to delete a record that does not exist anymore.

It is a classic problem.

The easiest way to get passed this hurdle is to do a redirect after the post. It is up to you to decide whether to redirect the users to, say, a confirmation/thank you page or to the same page.

As for the latter, add the following at the end of your grid event logics:



     Response.Redirect(Request.Url.AbsoluteUri);



After your updates have been made, the page will redirect to itself and prevent the event from firing again.

No comments:

Post a Comment