
Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Sorry let me explain.
Whenever I (or others) ask this question in forums the first thing people
say is:
"If you are populating your DropDownList in Page_Load then you might be
overwriting your values upon postback."
I'm just trying to point out that I am aware of this possibility and this is
not the case.
> Anyway, if you move the initial population of the DropDownList controls out
> of Page_Load and into Page_Init, everything should be fine...
Why is this. You're right it has solved my problem but I've never had to do
this before, why now? Surely if I call it on page init the values should be
overwritten??? Thanks for the help if you could just take 5 seconds to
explain why I'd apprectiate it.
Thanks again
Chris
> > Before you ask, yes I am using Page_Load to handle the PostBack
>
[quoted text clipped - 3 lines]
> Anyway, if you move the initial population of the DropDownList controls out
> of Page_Load and into Page_Init, everything should be fine...
Mark Rae [MVP] - 24 Sep 2007 13:28 GMT
> I'm just trying to point out that I am aware of this possibility and this
> is
> not the case.
S'OK - I understood...
>> Anyway, if you move the initial population of the DropDownList controls
>> out
[quoted text clipped - 6 lines]
> overwritten??? Thanks for the help if you could just take 5 seconds to
> explain why I'd apprectiate it.
Page life cycle: http://msdn2.microsoft.com/en-us/library/ms178472.aspx
Page_Load is just one of the events that happen when a page loads. However,
these events happen in a specific order, and several things occur in each of
the events (usually)...
One of the events that happens during Page_Load is that, for a postback),
control properties are loaded from ViewState and control state. If you also
write code to populate those controls in the Page_Load event, there's no
guarantee that your code will run before the ViewState is reapplied.
Sometimes it does, sometimes it doesn't...
Populate your controls in Page_Init, however, and you will never encounter
this problem...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Chris Gilbert - 24 Sep 2007 15:46 GMT
Cool, thanks for the help Mark
> > I'm just trying to point out that I am aware of this possibility and this
> > is
[quoted text clipped - 27 lines]
> Populate your controls in Page_Init, however, and you will never encounter
> this problem...