Page_Load is firing twice in ASP.NET page

前端 未结 16 1552
闹比i
闹比i 2020-12-08 09:57

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 loa

16条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 10:18

    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...

提交回复
热议问题