By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

Page_Load executes before aspx is rendered?

P: n/a
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 ID="DropDownList1" runat="server" </
asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

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.
Jan 30 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <gn********@gmail.comwrote in message
news:eb**********************************@f10g2000 hsf.googlegroups.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 ID="DropDownList1" runat="server" </
asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

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.

Jan 30 '08 #2

P: n/a
On Jan 30, 10:59*am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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?
Jan 30 '08 #3

P: n/a
Yes.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"gnewsgroup" <gn********@gmail.comwrote in message
news:0d**********************************@s8g2000p rg.googlegroups.com...
On Jan 30, 10:59 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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?
Jan 30 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.