views:

1800

answers:

6

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?

A: 

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

Mehrdad Afshari
+1  A: 

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
    }
}
Tyalis
+2  A: 

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
A: 

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
+1  A: 

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
A: 

Inside your tag put this:

EnableViewState="false"

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