Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Why is my Page_Load called twice? I'm using VS 2008 and I see this when I put a break on Page_Load and step through it. First time isPostback is true, second time it's false.

Here's my aspx page:
-------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="STN.test" %>

<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:LoginView ID="LoginView2" runat="server">
            <anonymoustemplate>
                <asp:Login ID="Login" runat="server">
                
            </anonymoustemplate>
            <loggedintemplate>
                <div>
                    LoggedInTemplate
                </div>
            </loggedintemplate>
        
    </div>
    </form>
</body>
</html>

Here's my aspx.cs page:
-------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace STN
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
Posted
Updated 26-Apr-11 14:58pm
v4

If you page contain src="#" remove them
 
Share this answer
 
Comments
CHill60 21-Jan-14 8:26am    
The question is over 2 years old!
Pages do not fire, but events can.
Do you mean each of Load and PreInit fires twice? You don't any event handlers added to event invocation lists (where this code is, either in code-behind of ASP XML?), but you can add them twice or add different handles to the same event.

—SA
 
Share this answer
 
Comments
Neuance 25-Apr-11 20:32pm    
As mentioned, the PreInit and PageLoad in both default.aspx and my masterpage file fire twice.
Sergey Alexandrovich Kryukov 25-Apr-11 21:33pm    
Thank you for confirmation... Hm. Did you check up what I suggest?
--SA
Neuance 25-Apr-11 23:02pm    
There is nothing else involved, page works fine until the submit on the Login.
Neuance 26-Apr-11 0:51am    
The first time through my default page isPostBack is true, second time it's false.
Sergey Alexandrovich Kryukov 26-Apr-11 1:01am    
Again, nothing else can be told based on the code you show.

You did not show the code where Page_Load and Page_PreInit are used. Where is it? All issue is around it, why didn't you show it?

Maybe if you show it the problem will be clear.
--SA
AutoEventWireup="true" causes this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900