By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Try removing "Handles MyBase.Load" from both Common.vb and Two.aspx

"bminder" <bm*****@b2btech.com> wrote in message news:<lv********************@speedfactory.net>...
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>

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.