I have created a date picker user control. I want to have a boolean
property, which I can set to determine whether the control defaults to
today's date. I have created a property which I set to true but when I
create the child controls it has always reset to false. I know it has been
set to true as I have trace written the value in the property "setter". Is
the create child controls event the wrong place to set the textbox, with the
date. Also have trace written the value in the create child controls and it
appears twice. Does this event fire twice? Regards, Chris.
Can you post the code you are using as a get/set accessor? Something a lot
of people make a mistake about is putting code into the page_load event of a
child control because they're used to doing it in the page. The page_load
takes place before that of the page's page_load event. That means that if
you set the property in the page it won't be accessible in the child
control, you need to use a later event, such as overriding the on-prerender
event.
Also, keep in mind that unless you're storing the property values into the
viewstate or another state management mechanism they values won't persist
unless they're specifically set. For example, to set a boolean property of a
child control into the viewstate you can use
public bool MyProperty
{
get {
if(ViewState["MyProperty"] != null)
return (bool)ViewState["MyProperty"];
else
return false;
}
set{ ViewState["MyProperty"] = value;}
}

Signature
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
>I have created a date picker user control. I want to have a boolean
>property, which I can set to determine whether the control defaults to
[quoted text clipped - 4 lines]
>the date. Also have trace written the value in the create child controls
>and it appears twice. Does this event fire twice? Regards, Chris.
Chris - 28 Jun 2007 23:14 GMT
I don't have access to the code but I am setting the propterty declaratively
in the design view on my aspx page (is that the same as setting it in the
onLoad) . Should I try and access that property in the on-prerender?
> Can you post the code you are using as a get/set accessor? Something a lot
> of people make a mistake about is putting code into the page_load event of
[quoted text clipped - 28 lines]
>>the date. Also have trace written the value in the create child controls
>>and it appears twice. Does this event fire twice? Regards, Chris.