Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
Hii,everyone
 
why this code write here in Page_PreRender()
and why not in page_Load() for example
code here :
 
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 17-Dec-12 19:57pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 395
1 Abhinav S 235
2 Nirav Prabtani 187
3 _Amy 160
4 Dave Kreskowiak 155
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,597
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100