Page_Load is firing twice in ASP.NET page

2019-01-17 05:47发布

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

15条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-17 06:19

Please find the solution here........

  1. Check if the Load events have Handlers for Base class and the child class Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load**

  2. If it is just Remove the Me.Load from the event , now check your page. Hope this may be useful and solve your issue.

查看更多
Animai°情兽
3楼-- · 2019-01-17 06:19

For me, this issue cropped up suddenly after the Oct. 2017 Windows update. I noticed that for pages made accessible to anonymous users via a Location element in web.config, it is now necessary to also grant access to any assets referenced by that page, for example images, stylesheets, etc. The below example grants anonymous access to the login page and the 'images' directory (aka folder):

<location path="login.aspx">
  <system.web>
    <authorization>
      <allow users="?" />
    </authorization>
  </system.web>
</location>
<location path="images">
  <system.web>
    <authorization>
      <allow users="?" />
    </authorization>
  </system.web>
</location>

Update: I found a second cause of Page_Load being called twice. In old, legacy code, some pages' .aspx.designer.cs files contained inconsistencies that apparently hadn't caused problems until now. Instead of attempting repair, I created new pages, which eliminated the double load event.

查看更多
老娘就宠你
4楼-- · 2019-01-17 06:28

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

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

查看更多
戒情不戒烟
5楼-- · 2019-01-17 06:28

I had the same problem and Solved.

I Checked my Global.ascx and My rewrite rules.

When the page requested, URL did not have "/" at the end of URL and a redirect happened from "x.com/x" to "x.com/x/" according to my configuration for SEO standards.

So anything works well and your internal links should have "/" at the end of URLs to avoid multiple loads.

查看更多
Juvenile、少年°
6楼-- · 2019-01-17 06:31

Please try making the changes mentioned in this link. http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/ccc75925-3460-497c-8471-fcebecd8d061

BTW I googled Page_Load Being called twice

查看更多
\"骚年 ilove
7楼-- · 2019-01-17 06:32

For me It was a blank image tag.

      <img src="#" />
查看更多
登录 后发表回答