Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,everyone

why this code write here in Page_PreRender()
and why not in page_Load() for example
code here :

C#
void Page_PreRender()
{
foreach (BaseValidator valControl in Page.Validators)
{
WebControl assControl =
(WebControl)Page.FindControl(valControl.ControlToValidate);
if (!valControl.IsValid)
assControl.BackColor = System.Drawing.Color.Yellow;
else
assControl.BackColor = System.Drawing.Color.White;
}
}
Posted

The code is in the Page_PreRender method as at this stage in the page lifecycle, all the controls on the page that are needed have been created. This isn't true for the Page_Load event.

Have a look here for more information
http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx[^]
 
Share this answer
 
It depends on your requirements.

Page Load : Perform actions common to all requests, such as setting up a database query. At this point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data.

Prerender :Perform any updates before the output is rendered. Any changes made to the state of the control in the prerender phase can be saved, while changes made in the rendering phase are lost.

ASP.NET Application and Page Life Cycle[^]
ASP.NET Page Life Cycle Overview[^]
Control Execution Lifecycle[^]
Difference between page_init, page_load and page_prerender events[^]
Page Events[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900