Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Can't access set property in custom control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris - 28 Jun 2007 19:30 GMT
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.
Mark Fitzpatrick - 28 Jun 2007 20:35 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.