ASP.NET - Prerender event - Asked By Ashwini on 15-Feb-12 01:34 AM

Hi

What is the use of prerender event and when we have to use this event iam confusing about this topic
plz anybody explain for me
D Company replied to Ashwini on 15-Feb-12 01:42 AM
Hello,

There are two things that i would like to tell you.

1.)As per my knowledge the word Prender  in page life cycle is not used as event(though it is an event), it's a "stage" that a page instance goes through Page_Init and Page_Load both occur during this stage.

2.)There is an event used in controls to perform any updates before the server control is rendered to the page. Any changes in the view state of the server control can be saved during this event. and in more detail, before the HTMl gets generated for any control it happens.

Hope its clear to you!!
Regards
D
Somesh Yadav replied to Ashwini on 15-Feb-12 01:53 AM

Hi,

Essentially PreRender event happens just before control/page renders itself. To be exact, Page's PreRenderComplete event is the last one in that cycle. Therefore PreRender stage's significance is in that it's the last place to change anything, so that changes contribute to page/control's state plus that they get rendered.

please see: http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Suchit shah replied to Ashwini on 15-Feb-12 01:55 AM
It is the event before the page is actually displayed on the screen. Or more technical, it happens BEFORE the render method gets called which creates the HTML code using the HtmlWriter. What's intersting is, that the viewstate isn' t updated and stored yet. Viewstate is the state of the webpage. If you need to change/update something which has to go into the viewstate, you should do this in the prerender event handler. If you do this after the render event, it will not be written to the viewstate, since the viewstate gets written just after the render event occurred.


Use this event to perform any updates before the server control is rendered to the page. Any changes in the view state of the server control can be saved during this event. Such changes made in the rendering phase will not be saved.

dipa ahuja replied to Ashwini on 15-Feb-12 01:56 AM
Whenver you run the aspx page, at the output you will get the html foramted output on the webpage. Its called rendering of page. 

PreRender is the event that takes place just before the HTML for a given control/page is generated (to later be sent to the browser).

You must check the page life cycle of asp.net to understand the each event of the asp.net page:

http://msdn.microsoft.com/en-us/library/ms178472.aspx