18

I have command button added in my asp.net grids. After performing an action using that button, we refresh the grid to reflect the new data. (basically this action duplicates the grid row).

Now when user refresh the page using F5, an alert message is displayed (to resend the information to server) if we select "retry", the action is repeated automatically.

I know this is a common problem in asp.net, how can we best handle this?

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
MOZILLA
  • 5,862
  • 14
  • 53
  • 59

7 Answers7

37

Search for GET after POST - http://en.wikipedia.org/wiki/Post/Redirect/Get - basically, redirect to the current page after you're finished processing your event.

Something like:

Response.Redirect(Request.RawUrl)

chris
  • 36,094
  • 53
  • 157
  • 237
2

If you think you don't need postback paradigm, you might want to look at ASP.NET MVC.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
2

The problem is that asp.net buttons perform form posts when you push a button. If you replace the button with a link your problem should go away. You can also use a button that performs a javascript function that sets the document.location to the address of your page.

Rune Grimstad
  • 35,612
  • 10
  • 61
  • 76
1

If I well understood, you simply have to check if you are in a post-back situation before populating your grid.
Assuming you do that on Page_Load, simply surround the operation with post-back test like this:

private void Page_Load(object sender, EventArgs e)
{
    if(!this.IsPostBack)
    {
        // populate grid
    }
}
Michaël Carpentier
  • 2,095
  • 1
  • 12
  • 13
1

You need to call response.Redirect(Request.Url.ToString());

or you can wrap the grid with updatepanel and after every command bind the datasource to grid

Barbaros Alp
  • 6,405
  • 8
  • 47
  • 61
1

Inside your <asp:Repeater> tag put this:

EnableViewState="false"

This will cause your control to refresh every time the page loads, no matter if it's a postback or not.

Carsten
  • 11,287
  • 7
  • 39
  • 62
-1

for example: if you click on 'button' system will catch the event 'button_click'. if you refresh the page, system will re execute again the same event. to don t have this problem, in your event insert : on your event

private void button_click(object sender, System.EventArgs e)
{
    button.Enabled =false;
    button.Enabled =true;
}

is what you meant?