0

While developing and testing locally, I am observing that if my aspx page contains internal css defined within <style> tag, the page_Load method will execute twice. If I remove it, it executes only once. I've never heard of this and can find no details online of anyone else having this. Seeking insight into this highly bizarre and inconvenient quirk. It applies to any internal css, not just this particular line, and will load twice if <style> tag is placed anywhere within page (header, body, or footer). Even if blank, the meer presence of <style> tags causes the page to load twice.

Here is the simplest form of a page that causes the double load:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestSimple.aspx.cs" Inherits="Portal.Web.Main.Portal.SalesTeam.TestSimple"  %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style>
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
            </div>
        </form>
    </body>
</html>

And here's the codebehind

namespace Portal.Web.Main.Portal.SalesTeam
{
    public partial class TestSimple : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("page loading");
        }
    }
}
  • Are you saying there are two Page_Load events fired in the codebehind for a single HTTP request? Or are there two HTTP requests? How have you determined it is executing twice exactly? – John Wu Dec 29 '22 at 00:14
  • yes that is right, two Page_Load events fired in codebehind for a single HTTP request. I have determined this by tracing and seeing that it gets to bottom of the method and then returns to the top and executes a second time. I have also included log steps and other output tests. – clarencekieran Dec 29 '22 at 18:46
  • You might be interested in [this answer](https://stackoverflow.com/a/17200584/2791540). It appears the author found about a half dozen reasons why `Page_Load` could be called twice. Any of them apply to you? – John Wu Dec 30 '22 at 07:46

1 Answers1

0

You have to post some sample markup. Preferable the MINIMUM amount that re-produces this error.

I have this web page markup.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestImage.aspx.vb" Inherits="TestWeb.TestImage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


         <style runat="server">
            .bigcheck input {width:20px;height:20px;cursor:pointer;float:left}
            .bigcheck label {float:left;margin-left:10px;margin-top:4px}            
            .bigcheck2 span {vertical-align:middle}
        </style>

</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
    </form>
</body>
</html>

And in code behind, I have this in the page load event.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Debug.Print("page load -- is postback = " & IsPostBack)

End Sub

Result when I run is this:

enter image description here

so, I don't see two post-backs, and I don't see the page load firing two times.

So, create a blank new web page, put in that style sheet. In the load event, put in a debug.print, and if it runs two times, then post this re-producible example for everyone here to try.

NONE of us at this point in time are able to re-produce this effect.

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
  • I have created a totally different solution with just one test page and am observing this situation is not happening. Which makes me think perhaps this double load issue is related to a parameter in web.config. But it's curious that the ` – clarencekieran Dec 29 '22 at 17:28
  • And if you create a blank test page in that existing site - say a web page that is not a page with master/child setup, and does that same blank page do the same thing? As I stated, post a working sample and re-producible error - else we just playing a game of darts in a room with the lights out, and we really can't help you. (ok, I see you posted a page in your comments (better to edit and post that in your main post so we can read it with greater ease). – Albert D. Kallal Dec 29 '22 at 18:17
  • thanks Albert. I have edited original post with code sample. Per your questions, yes that's right...a blank page with no master does the same thing. Please see above with my sample page that causes the issue. – clarencekieran Dec 29 '22 at 18:48
  • Ok, nothing stands out that would suggest this issue. We assume this page is not secured and does not require a logon to use. Maybe friendly ulr's is turned on, but again, I can't see that being the issue. – Albert D. Kallal Dec 29 '22 at 18:51