I have an asp.net web application that has been behaving strangely for some time now.
When I click any button, the Page_Load method of the various pages always enters 2 times.
The first time the IsPostback parameter has the correct value, and the second it doesn’t.
I read that applications that passes more times in Page_Load could have href or src empty but in my page I can’t find anything.
one page is https://almarea.it/login
The code of the button in aspx page is
<asp:LinkButton runat="server" ID="lnkBtnLogin" class="btn btn-default btn-lg btn-block" OnClick="lnkBtnLogin_Click" Text="LOGIN"></asp:LinkButton>
The code in the code behind is quite long but if I try to remove all that code and let it empty the problem is still there.
protected void lnkBtnLogin_Click(object sender, EventArgs e)
{
}
So the problem is not here.
I checked for empty src and empty href but I didn’t find anything.
2
Answers
Check your browser dev tools (the network tab) and look at what is initiating the second request.
Are you using a master + child page? In that case, both master page load, and child page load triggers.
It also possible that your button code does a response.redirect back to the same page, which of course would also cause a double page load. The other possible is use of postback URL in the button. In that case, you don’t want to have a event stub for that button, so either remove postbackURL from the button, or remove the event stub in code behind – don’t have both.
You could post just the button markup, and then say the button event code stub.
The other possible is some JavaScript code that posts-back to the same page.