Asp.net page_load function is loading twice.. hence it affects my page performance. Does anyone know the reason it is loading twice.
No, iam not calling the page load function anywhere...
Your web form has a method called Page_Load. This method is called each time your page is loaded. This includes: 1. The first time the page is loaded, e.g., when a user enters the url to it or clicks on a link to it.
IsPostBack is a property of the Asp.Net page that tells whether or not the page is on its initial load or if a user has perform a button on your web page that has caused the page to post back to itself.
AutoEventWireup is an attribute in Page directive. AutoEventWireup is a Boolean attribute that indicates whether the ASP.NET pages events are auto-wired. AutoEventWireup will have a value true or false. By default it is true.
Just ran into this problem, and thought I would post an answer summarizing what I found, plus my actual issue.
1. img tags with src="" or Image tags with ImageUrl="" 2. Using AutoEventWireup="true" and adding a page handler 3. Having manually added the event handler (more common for C# than VB) 4. Handling both MyBase.Load and Me.Load 5. Variation on the missing img src, body { background-image: url(); } 6. Rewrite rule and missing favicon.ico
and finally my issue....
My page inherited from a class that included a Page Load handler, which inherited from a class with a Page Load Handler.
Public Class C1 Inherits System.Web.UI.Page Protected Overridable Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub End Class Public Class C2 Inherits C1 Protected Overrides Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load MyBase.PageLoad(sender, e) End Sub End Class Public Class MyPage Inherits C2 Protected Overrides Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) MyBase.PageLoad(sender, e) End Sub End Class
I tested this, and if you put a Handles on the method in MyPage, it will get hit 3 times...
It is not you calling the page load function twice, that is the way ASP.NET works. The page posts to itself, thus calling the page_load function, when any Server controls on the page are fired (those which as set to postback).
What you need to do is to put some checks to differentiate between an initial page load and a post back
if(!IsPostBack) { //Code when initial loading } else { // code when post back }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With