Reputation: 93384
When I click multiple times on a button that performs a server-side redirect using ASP.NET, thing can get weird. Sometimes I get ViewState errors, other times the page is only partially loaded.
The code for the OnClick
event of the button is simple:
HttpContext.Current.Response.Redirect(targetUrl);
If I have something like:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Something();
}
}
in the page I'm redirecting to, the Something()
function won't be called if the button is pressed more than once in rapid succession.
Is this normal? What could be the cause of these weird issues when pressing buttons multiple times quickly?
Upvotes: 0
Views: 1292
Reputation: 309
Ok as far as i know i could explain the weird result as below: the first time you click the button, server will do the redirect and since its the first time you hit the page from another page it will not be a postback, but the second time you click the button in the server you will be already redirected and it will see the request as postback because on the server your already on that page, since its redirected you in the first time, at the end you will get the response of the last click which will be a postback in the server.
to avoid this issue, you should make a loading panel appear on the button, or disable the button before you go to the server using javascript.
Upvotes: 1