I’m experiencing something weird, that I need help understanding. When I use a link tag with the "href" attribute set to "#", it causes the Page Load event to run twice.
For example, in the following link tag, I’m using "#" as the value for the "href" attribute. I’m using this in place of using a real "shorcut icon" and only to avoid the javascript warning/error. So, I could simply remove it, but I’d like to understand what is goin on (or how to fix it, without removing it):
<link rel="shortcut icon" href="#">
Sample HTML:
<!doctype html>
<html lang="en">
<head runat="server">
<title>My Example</title>
<!-- The "href=#" in the following link tag triggers the 'Page load' event to run twice. -->
<link rel="shortcut icon" href="#">
</head>
<body>
<form id="form1" runat="server">
<h1>My Example</h1>
</form>
</body>
</html>
Sample VB.NET Code Behind Page:
Partial Class myexample
Inherits System.Web.UI.Page
Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
'This is triggered twice.
End Sub
End Class
This also happens with using it for "stylesheet" link tags as shown below:
<link rel="stylesheet" href="#" />
2
Answers
I found a solution on Stack Overflow at the link below. It solves the javascript error, which was my original intent, while preventing the double page load. The answer is provided a few posts down.
Link:
Link to Forum Post
ASP might just be doing this because # means "the current page" (like when you set # to be the value of an
<a>
tag and click it), so when you try to do this elsewhere, it is reading it wrong and attempting to load the current page as the resource for the favicon, therefore loading the page twice.