Code in MasterPages

  • Thread starter Thread starter Jeff Lynch
  • Start date Start date
J

Jeff Lynch

I need to call a class on every web page in a site. In ASP.NET 1.1 I would
call this class before the Page_Load event in each web page's code-behind
file since it needs to run before the web page loads.

In ASP.NET 2.0 can I do the same thing by calling the class on the
MasterPage's code-behind before it's Page_Load and will this run before the
content page's Page_Load?
 
No. The thing to know about master pages is that they really don't
"master" anything - they work by injecting themselves into the content
page's control hierarchy. So, the "master" becomes just another child
control, and the content page's Page_Load will fire off first.

What I'd recommend is a base class for all of your pages to derive
from. The base class could hook the Init event and do the work in one
place.
 
Thanks for Scott's informative inputs.

Hi Jeff,

As Scott has mentioned, Master page is mainly focus on UI consistency
rather than Page inheritance hierarchy. So for performing a common
operation for all pages by defining the fucntion in a center place, I'd
suggest you consider Scott's suggest by defining a common base page class
for those pages which will share the operation.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| From: Scott Allen <[email protected]>
| Subject: Re: Code in MasterPages
| Date: Thu, 08 Sep 2005 09:36:59 -0400
| Message-ID: <[email protected]>
| References: <[email protected]>
| X-Newsreader: Forte Agent 1.8/32.548
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: dyn-170-235-0.myactv.net 24.170.235.0
| Lines: 1
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
2.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:342607
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| No. The thing to know about master pages is that they really don't
| "master" anything - they work by injecting themselves into the content
| page's control hierarchy. So, the "master" becomes just another child
| control, and the content page's Page_Load will fire off first.
|
| What I'd recommend is a base class for all of your pages to derive
| from. The base class could hook the Init event and do the work in one
| place.
|
| --
| Scott
| http://www.OdeToCode.com/blogs/scott/
|
| On Thu, 8 Sep 2005 08:21:43 -0500, "Jeff Lynch"
|
| >I need to call a class on every web page in a site. In ASP.NET 1.1 I
would
| >call this class before the Page_Load event in each web page's
code-behind
| >file since it needs to run before the web page loads.
| >
| >In ASP.NET 2.0 can I do the same thing by calling the class on the
| >MasterPage's code-behind before it's Page_Load and will this run before
the
| >content page's Page_Load?
|
|
 
Scott & Steven,

Thanks for the input. I'm taking your advice and creating a common base page
class for this site.
 
You're welcome Jeff,

Good luck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Jeff Lynch" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Code in MasterPages
| Date: Sat, 10 Sep 2005 11:44:20 -0500
| Lines: 87
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: cpe-24-167-36-137.houston.res.rr.com 24.167.36.137
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:123690
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Scott & Steven,
|
| Thanks for the input. I'm taking your advice and creating a common base
page
| class for this site.
|
| --
| Jeff Lynch
| "A BizTalk Enthusiast"
| http://codebetter.com/blogs/jeff.lynch
|
|
| | > Thanks for Scott's informative inputs.
| >
| > Hi Jeff,
| >
| > As Scott has mentioned, Master page is mainly focus on UI consistency
| > rather than Page inheritance hierarchy. So for performing a common
| > operation for all pages by defining the fucntion in a center place, I'd
| > suggest you consider Scott's suggest by defining a common base page
class
| > for those pages which will share the operation.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| > --------------------
| > | From: Scott Allen <[email protected]>
| > | Subject: Re: Code in MasterPages
| > | Date: Thu, 08 Sep 2005 09:36:59 -0400
| > | Message-ID: <[email protected]>
| > | References: <[email protected]>
| > | X-Newsreader: Forte Agent 1.8/32.548
| > | MIME-Version: 1.0
| > | Content-Type: text/plain; charset=us-ascii
| > | Content-Transfer-Encoding: 7bit
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: dyn-170-235-0.myactv.net 24.170.235.0
| > | Lines: 1
| > | Path:
| >
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
| > 2.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:342607
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | No. The thing to know about master pages is that they really don't
| > | "master" anything - they work by injecting themselves into the content
| > | page's control hierarchy. So, the "master" becomes just another child
| > | control, and the content page's Page_Load will fire off first.
| > |
| > | What I'd recommend is a base class for all of your pages to derive
| > | from. The base class could hook the Init event and do the work in one
| > | place.
| > |
| > | --
| > | Scott
| > | http://www.OdeToCode.com/blogs/scott/
| > |
| > | On Thu, 8 Sep 2005 08:21:43 -0500, "Jeff Lynch"
| > |
| > | >I need to call a class on every web page in a site. In ASP.NET 1.1 I
| > would
| > | >call this class before the Page_Load event in each web page's
| > code-behind
| > | >file since it needs to run before the web page loads.
| > | >
| > | >In ASP.NET 2.0 can I do the same thing by calling the class on the
| > | >MasterPage's code-behind before it's Page_Load and will this run
before
| > the
| > | >content page's Page_Load?
| > |
| > |
| >
|
|
|
 

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

Back
Top