Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

webforms - Page_Load is firing twice in ASP.NET page

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...