Refresh the page after a postback action in asp.net

半城伤御伤魂 提交于 2019-12-18 12:16:42

问题


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?


回答1:


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)




回答2:


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




回答3:


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.




回答4:


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
    }
}



回答5:


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




回答6:


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.




回答7:


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?



来源:https://stackoverflow.com/questions/553227/refresh-the-page-after-a-postback-action-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!