473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Can't access set property in custom control

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.
Jun 28 '07 #1
2 2051
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;}
}

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Chris" <no****@nospam.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>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.

Jun 28 '07 #2
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?
"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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;}
}

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Chris" <no****@nospam.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>>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.


Jun 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sushil Srivastava | last post by:
Hi Guys, Would you be able to help me using C# GUI (with user interface component) in my MFC application. I have used managed extension, COM-interops, etc but problem is this C# component has...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
by: Sanjay Pais | last post by:
I built a custom control for all the basic web.ui.controls like textbox, label, checkbox etc etc. I added my custom attribute called ApplySecurity to the html in the page. However, when I cycle...
10
by: Miro | last post by:
I wanted certain text boxes ( only certain ones ) to always be Trim'd so that spaces are not in the begining, nor the end of the text entered. I created my own "Handle ?" - i hope thats the...
0
by: Walter | last post by:
Hi, can someone please help me with my custom control viewstate problem....I haven't slept for hours trying to get this fixed. I am making two custom controls which will be included on a single...
1
by: --== Alain ==-- | last post by:
Hi, I have a huge problem... My property does not appear in the "propertyGrid" of "test Container", when i test my custom control. Here is the custom control code : namespace...
6
by: forest demon | last post by:
i have a custom control that gets loaded at runtime. i need to be able to access a property of a control thats part of the main form, through the clcik event of the custom control. i may be...
2
by: R.A.F. | last post by:
Hi, I have a custom control in which i have a collection property named "Columns". this collection property add/remove column objects. in my Column class i have a property named Alignment...
7
by: adiel_g | last post by:
Hello Everyone, I created a custom control. On the CreateChildControls, I added a textbox to the control as follows: // TextBox TextBox txtValue = new TextBox(); txtValue.ID = "txtValue"; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.