A
Alan Silver
Hello,
I'm having rather a problem with user control. It is a fairly simple
affair (see my other threads for more details) that shows a date and
time in five drop down controls.
I had private member variables for the day, month, year, hour and
minute, and the public property that sets the DateTime simply stored the
relevant numbers in these variables.
Then, in the Page_Load event, I had something like ...
if (!PostBack) {
drpDay.SelectedIndex = m_Day;
drpMonth.SelectedIndex = m_Month;
// and so on ...
}
This worked fine when the control was tested, but gave odd results when
used on a real form. I realised after a while that the reason was that
the real form didn't display the control when the page was first loaded.
It was only at some point later that the control was displayed, which
was on a postback for the main page. The user control was picking up
that postback and so never firing the code that set the drop down
controls.
I have tried ninety seven different ways of getting around this problem
and I'm going round in circles. Could anyone explain how I get around
this?
Basically what I want is to be able to detect when the control is first
loaded, irrespective of whether or not it is a postback. I tried simply
using a member variable to flag this, but that didn't work either ;-(
I can't remember exactly what went wrong as I've tried so many other
things since, but I know it went badly wrong.
Any help would be greatly appreciated as I feel I'm making very heavy
weather out of a (presumably) simple problem. TIA
I'm having rather a problem with user control. It is a fairly simple
affair (see my other threads for more details) that shows a date and
time in five drop down controls.
I had private member variables for the day, month, year, hour and
minute, and the public property that sets the DateTime simply stored the
relevant numbers in these variables.
Then, in the Page_Load event, I had something like ...
if (!PostBack) {
drpDay.SelectedIndex = m_Day;
drpMonth.SelectedIndex = m_Month;
// and so on ...
}
This worked fine when the control was tested, but gave odd results when
used on a real form. I realised after a while that the reason was that
the real form didn't display the control when the page was first loaded.
It was only at some point later that the control was displayed, which
was on a postback for the main page. The user control was picking up
that postback and so never firing the code that set the drop down
controls.
I have tried ninety seven different ways of getting around this problem
and I'm going round in circles. Could anyone explain how I get around
this?
Basically what I want is to be able to detect when the control is first
loaded, irrespective of whether or not it is a postback. I tried simply
using a member variable to flag this, but that didn't work either ;-(
I can't remember exactly what went wrong as I've tried so many other
things since, but I know it went badly wrong.
Any help would be greatly appreciated as I feel I'm making very heavy
weather out of a (presumably) simple problem. TIA