Page_Load executes before aspx is rendered?

Page_Load executes before aspx is rendered?

am 30.01.2008 16:48:15 von gnewsgroup

This might have been discussed before, but I haven't been able to dig
it out.

I ask because I notice something interesting.

Suppose, I have the following controls in a web form.

asp:DropDownList>


Suppose, in Page_Load, I want to do:

Label1.Text = DropDownList1.SelectedItem.Text;

If I bind the DropDownList right in the aspx file through
SqlDataSource, Label1.Text is empty when I check out the application
in the browser.

If I bind the DropDownList in the code behind, and in Page_Load, I do:

BindTheDropDownList();
Label1.Text = DropDownList1.SelectedItem.Text;

Label1.Text does have the text value of the 0th item of the
DropDownList.

Therefore, I think that at Page_Load, the binding processes in the
ASPX file are not done yet. Am I right?

Thanks.

Re: Page_Load executes before aspx is rendered?

am 30.01.2008 16:59:36 von Eliyahu Goldin

Yes. The binding of this sort takes place in the PreRender event.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"gnewsgroup" wrote in message
news:eb05bd43-8abf-4f95-8098-63a7a39bea39@f10g2000hsf.google groups.com...
> This might have been discussed before, but I haven't been able to dig
> it out.
>
> I ask because I notice something interesting.
>
> Suppose, I have the following controls in a web form.
>
> > asp:DropDownList>
>
>
> Suppose, in Page_Load, I want to do:
>
> Label1.Text = DropDownList1.SelectedItem.Text;
>
> If I bind the DropDownList right in the aspx file through
> SqlDataSource, Label1.Text is empty when I check out the application
> in the browser.
>
> If I bind the DropDownList in the code behind, and in Page_Load, I do:
>
> BindTheDropDownList();
> Label1.Text = DropDownList1.SelectedItem.Text;
>
> Label1.Text does have the text value of the 0th item of the
> DropDownList.
>
> Therefore, I think that at Page_Load, the binding processes in the
> ASPX file are not done yet. Am I right?
>
> Thanks.

Re: Page_Load executes before aspx is rendered?

am 30.01.2008 17:11:48 von gnewsgroup

On Jan 30, 10:59=A0am, "Eliyahu Goldin"
wrote:
> Yes. The binding of this sort takes place in the PreRender event.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net =

>

Thank you. I think by "binding of this sort", you are referring to
the kind of binding in aspx file through SqlDataSource?

Re: Page_Load executes before aspx is rendered?

am 30.01.2008 17:21:57 von Eliyahu Goldin

Yes.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"gnewsgroup" wrote in message
news:0ddeabb7-eed6-4863-932b-7dad48fe91dd@s8g2000prg.googleg roups.com...
On Jan 30, 10:59 am, "Eliyahu Goldin"
wrote:
> Yes. The binding of this sort takes place in the PreRender event.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>

Thank you. I think by "binding of this sort", you are referring to
the kind of binding in aspx file through SqlDataSource?

Re: Page_Load executes before aspx is rendered?

am 30.01.2008 21:31:50 von Patrice

I copied these notes out of a base class I had handy...

// Events in ASP.NET Master and Content Pages
// http://msdn2.microsoft.com/en-us/library/dct97kc3.aspx

//1.) Master page controls Init event.
//2.) Content controls Init event.
//3.) Master page Init event.
//4.) Content page Init event.
//5.) Content page Load event.
//6.) Master page Load event.
//7.) Content controls Load event.
//8.) Content page PreRender event.
//9.) Master page PreRender event.
//10.) Master page controls PreRender event.
//11.) Content controls PreRender event.

//http://www.dotnetspider.com/qa/Question27787.aspx
//Page_Init (VB) OnInit (C#)
//This is the first step in a Web form’s life cycle.
//The server controls are loaded and initialized from the Web form’s view
state.


//Page_Load
//The server controls are loaded in the Page object. View state information
is available
// at this point, so this is where we may put code to change control
settings or display
// text on the page.

//Page_PreRender
//The page object has been compiled and is about to be rendered.

//Page_Unload
//The page is unloaded from memory.

//Page_Disposed
//The Page object is released from memory. This is the last event in the
life of a Page object.

//Page_Error
//An unhandled exception occurs.

//Page_AbortTransaction
//A transaction is aborted.

//Page_CommitTransaction
//A transaction is accepted.

//Page_DataBinding
//A server control on the page binds to a data source.


"Eliyahu Goldin" wrote in
message news:%23ueqdx1YIHA.5396@TK2MSFTNGP02.phx.gbl...
> Yes.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "gnewsgroup" wrote in message
> news:0ddeabb7-eed6-4863-932b-7dad48fe91dd@s8g2000prg.googleg roups.com...
> On Jan 30, 10:59 am, "Eliyahu Goldin"
> wrote:
>> Yes. The binding of this sort takes place in the PreRender event.
>>
>> --
>> Eliyahu Goldin,
>> Software Developer
>> Microsoft MVP
>> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>>
>
> Thank you. I think by "binding of this sort", you are referring to
> the kind of binding in aspx file through SqlDataSource?
>

Re: Page_Load executes before aspx is rendered?

am 30.01.2008 21:45:08 von gnewsgroup

On Jan 30, 3:31 pm, "clintonG" wrote:
> I copied these notes out of a base class I had handy...
>
> // Events in ASP.NET Master and Content Pages
> //http://msdn2.microsoft.com/en-us/library/dct97kc3.aspx
>
> //1.) Master page controls Init event.
> //2.) Content controls Init event.
> //3.) Master page Init event.
> //4.) Content page Init event.
> //5.) Content page Load event.
> //6.) Master page Load event.
> //7.) Content controls Load event.
> //8.) Content page PreRender event.
> //9.) Master page PreRender event.
> //10.) Master page controls PreRender event.
> //11.) Content controls PreRender event.
>
> //http://www.dotnetspider.com/qa/Question27787.aspx
> //Page_Init (VB) OnInit (C#)
> //This is the first step in a Web form's life cycle.
> //The server controls are loaded and initialized from the Web form's view
> state.
>
> //Page_Load
> //The server controls are loaded in the Page object. View state information
> is available
> // at this point, so this is where we may put code to change control
> settings or display
> // text on the page.
>
> //Page_PreRender
> //The page object has been compiled and is about to be rendered.
>
> //Page_Unload
> //The page is unloaded from memory.
>
> //Page_Disposed
> //The Page object is released from memory. This is the last event in the
> life of a Page object.
>
> //Page_Error
> //An unhandled exception occurs.
>
> //Page_AbortTransaction
> //A transaction is aborted.
>
> //Page_CommitTransaction
> //A transaction is accepted.
>
> //Page_DataBinding
> //A server control on the page binds to a data source.
>

Nice documentation, now, that's clear.