Why does page_load fire twice when inheriting from a common overridable Page_Load

B

bminder

In the asp.net pages below, Common.vb has an overridable Page_Load sub. In
the consuming page, Two.aspx, the Page_Load sub is inherited, but for some
reason it (Overrides Sub Page_Load) executes twice.

In another "regular" asp.net page that inherits only from its own codebehind
page, the page load only executes once as you'd expect.

Any ideas why the page_load fires twice in the former example?

Thanks,

Brent

============
Common.vb:
============
Imports System
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls

Public Class Common
Inherits Page
Protected WithEvents lblHeader As Label
Overridable Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lblHeader.Text = "Overridable common text."
End Sub
End Class

============
Two.aspx:
============
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Common.vb"
Inherits="MyTest.Common"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<form method="post" runat="server">
<asp:Label Runat=server ID=lblHeader />
</form>
<script language=vb runat=server>
Overrides Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'mybase.Page_Load(sender, e)
lblHeader.Text &= "<br>Page TWO Overriding page load<br><a
href='./one.aspx'>Back to Page One</a>"
end sub
</script>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top