asp.net webform page_load run twice

HJ Kang 1 Reputation point
2020-02-07T10:15:55.007+00:00

Hello.
I have been developing using ASP.NET program language for more than 10 years.
Today the project was so slow that I tried debugging.
Debugging results were very shocking.

I made an empty web project, and I made a webform.aspx
A code that creates a very simple method and executes it in Page_Load.

No events occur except one page call.
But Page_Load was executed twice.

As far as my knowledge is concerned, Page_Load will only be executed once upon loading the first page before the event is issued. This was the basis of ASP.NET C#.
Is my knowledge wrong?

Here the test() method runs twice.
Am I wrong?

----------------------

public partial class WebForm6 : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        test();  <-- calling twice  
    }  

    private void test() <-- calling twice  
    {  
        int a = 1;  
        int b = 2;  
        Response.Write(a * b);  
    }  
}  

----------------------

2675-aspent-qa.png

Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
313 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Somnath Shukla 411 Reputation points
    2020-02-07T11:12:59.62+00:00

    Page_Load event will fire only once. unless you do gain Post back again using some button click or ajax call. After adding if(!Page.IsPostBack) check did it fired only once. can you share the response also.

    0 comments No comments

  2. Jerryzy 10,566 Reputation points
    2020-02-10T07:50:48.85+00:00

    Hi HJKang,

    Welcome to Q&A Forum.

    This forum mainly discussed about Partner Center API related question, as this question is more related with .NET Web Development, I suggest you can create a new thread in ASP.NET Forum below:

    ASP.NET Forums

    Thanks

    Best Regards