|
 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

May 17th, 2011, 04:07 AM
|
Authorized User
|
|
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Page_Prerender
Hi all, can anyone tell me the exact sequence the below code runs in. The line
this.PreRender += newEventHandler(Page_Prerender); in particular, what is it, what does it do and at what stage does it run
Correct me if i am wrong but in the BasePage class the Page_Prerender method is called first through the page life cycle... what goes on next in the below code. I am ok with Comparing the contents of the Title bit.
Many thanks
Mark
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
///<summary>
/// Summary description for BasePage
///</summary>
publicclassBasePage : System.Web.UI.Page
{
//no instance variables
public BasePage()
{
this.PreRender += newEventHandler(Page_Prerender);
// TODO: Add constructor logic here
}
//methods
privatevoid Page_Prerender (Object sender, EventArgs e)
{
if (this.Title == "Untitled page" || String.IsNullOrEmpty (this.Title))
{
thrownewException ("Page does not have a title....");
}
}
}
|

May 17th, 2011, 06:21 AM
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
|
|
Hi,
the PreRender event triggers right after the init and load events are completed and before the render and unload event.
Which means that this event triggers after your page (and child controls) have initialized, viewstate has been reconstructed and postback events have been processed. Looks like a logic place to put a check on empty page title.
Hope this helps..
|

May 17th, 2011, 06:53 AM
|
Authorized User
|
|
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Hi Disel2010, your reply is much appreciated but my original questions stand. Does the Page_Prerender method get called automatically by the page life cycle or does the this.PreRender += newEventHandler(Page_Prerender); in the constructor call the method. I seem to be having a brain freeze with this one.
Thanks again
Mark
|

May 17th, 2011, 06:56 AM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
Hi Mark,
The event is raised by the Page class automatically. The code in the constructor then assigns a method that will be called to handle the event.
Hopenthis helps,
Imar
|

May 17th, 2011, 10:00 AM
|
Authorized User
|
|
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Hi Imar and many thanks for your reply. "The event is raised by the Page class automatically.!" the event being the Page_Prerender. That's good, i am getting there.
"The code in the constructor then assigns a method that will be called to handle the event." As below
public BasePage()
{
this.PreRender += newEventHandler(Page_Prerender);
}
How does the page class know to run the BasePage() constructor?. I guess this is where my problem is. I know this is wrong but the way I am looking at it the code should be something like, the Page_Prerender method called from within the Page_Prerender class.
Public Page_Prerender()
{
// Page_Prerender code
}
Many thanks
Mark
|

May 17th, 2011, 10:09 AM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
The Page class *is* the BaseClass. When you create a page, you let it inherit BasePage. So, the request for a page is handled by your BasePage. Its base class (eg. System.Web.UI.Page) then raises the event which is handled by the method you assign in the constructor of the BasePage class.
So, actually, Page and BasePage are more or less merged into a single class. The BasePage can do whatever Page can (but not vise versa) including handling the PreRender event.
Does this clarify things?
Imar
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

May 20th, 2011, 06:15 AM
|
Authorized User
|
|
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Yes, this makes it clear.
Many thanks
Mark
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
Issue with Page_PreRender |
webdeveloper |
C# |
0 |
October 17th, 2007 12:37 PM |
|
 |
All times are GMT -4. The time now is 03:59 AM.
|