473,594 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Controls with object type properties.

Guys,

I've written a custom control (or at least tweaked someone else's!) in C# to
be used on forms (rather than asp.net forms). The control is a date time
picker, but its Value property returns a special date time object we have
written, when a date is selected. The property object's class is called
OptionalDateTim e. This is basically to allow blank dates, and is useful when
a date to be entered is not mandatory.

This is the problem: If I draw the control on a form, it works fine, and I
can read the Value property of my control using the Value property. However,
for some reason, it suddenly stops working at random!

I think the problem is to do with code created automatically in the
InitializeCompo nent() method. When the control is first drawn on the form,
this gets created:

this.lockableOp tionalLightDate TimePicker1.Val ue =
((HCS.DataTypes .Time.OptionalD ateTime)(resour ces.GetObject(" lockableOptiona lLightDateTimeP icker1.Value")) );

When it stops working, the code is the same as listed here, but I start
getting an error with this line of code. The problem is hard to recreate
reliably at the moment, but I am working on it. I’m pretty sure the error is
the “Object reference not set to an instance of an object” exception, but I
will confirm this.

Has anyone got any ideas? Is it bad practice to have a Value property that
returns an object type? I wouldn’t have thought so, since other Microsoft
controls do this; for instance, when colors are involved.

Your help in this matter would be greatly appreciated!

Thanks,

Steve.

--
Steve Barker
Development Manager
Hanlon Computer Systems
Jul 21 '05 #1
3 1530
Hi Steve,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are receiving a
NullReferenceEx ception when using your own control on a windows form app.
The exception seems to be thrown from InitializeCompo nent method. If there
is any misunderstandin g, please feel free to let me know.

From the exception message, I think there might be some references that
might not point to a valid object in the following statement.

this.lockableOp tionalLightDate TimePicker1.Val ue =
((HCS.DataTypes .Time.OptionalD ateTime)(resour ces.GetObject(" lockableOptiona l
LightDateTimePi cker1.Value"))) ;

For troubleshooting , I think you can try to set a breakpoint when the
exception is thrown and add the following watches in the watch window.

this.lockableOp tionalLightDate TimePicker1
resources
resources.GetOb ject("lockableO ptionalLightDat eTimePicker1.Va lue")

If one of them is a null reference, please check if you have set it to a
valid object before. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
Kevin,

Thanks for your prompt reply!

As I say, we haven't been able to find a sure way to get an exact repro yet,
although we are working on it. I just wondered if anyone could tell what was
wrong without an exact repro!

Yes, your summary of the problem is correct; we have written a control. When
the control is placed on a Windows form, the following code (and some other
property setting code) is written to the InitializeCompo nent method:

this.lockableOp tionalLightDate TimePicker1.Val ue =
((HCS.DataTypes .Time.OptionalD ateTime)(resour ces.GetObject(" lockableOptiona lLightDateTimeP icker1.Value")) );

When the form is then run, the form and the control both work correctly.

However, after an in determinant length of time, this exact same line of
code starts to cause problems! When the form’s InitializeCompo nent fires,
this exact same line of code causes an exception. Now again, because the
problem is hard to repro, I cannot confirm that the exception is a
NullReferenceEx ception, although I’m pretty sure that is what it was. As soon
as I can get a repro, I’ll update this post.

The thing is, this line of code is looking at a resource file to find out
what value to initially give to my date picker control. It is strange how it
can work fine for a while and then stop working; I never directly edit the
forms resource file, and so the entry against the control’s Value property
should not change! Why does it stop working? When I can get a repro, I’ll try
your suggestion.

Have you any other suggestions in the meantime? I wondered if you need to
specify an attribute within the control to show that a property takes a
reference type rather than a value type?

Thanks again for your help, and apologies for being so vague. I’ll pin
things down more when I can get a repro.

Many thanks,

Steve.


"Kevin Yu [MSFT]" wrote:
Hi Steve,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are receiving a
NullReferenceEx ception when using your own control on a windows form app.
The exception seems to be thrown from InitializeCompo nent method. If there
is any misunderstandin g, please feel free to let me know.

From the exception message, I think there might be some references that
might not point to a valid object in the following statement.

this.lockableOp tionalLightDate TimePicker1.Val ue =
((HCS.DataTypes .Time.OptionalD ateTime)(resour ces.GetObject(" lockableOptiona l
LightDateTimePi cker1.Value"))) ;

For troubleshooting , I think you can try to set a breakpoint when the
exception is thrown and add the following watches in the watch window.

this.lockableOp tionalLightDate TimePicker1
resources
resources.GetOb ject("lockableO ptionalLightDat eTimePicker1.Va lue")

If one of them is a null reference, please check if you have set it to a
valid object before. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
Hi Steve,

Thanks for you clarify! Besides the advice from my last post. I think you
can also check the other parts of the code to see if any code has cleared
the resource lockableOptiona lLightDateTimeP icker1. Also I don't think we
need to put .Value follows the resource name. Is .Value a part of resource
name? If not, please try to remove it.

If that still doesn't help, I would be happy to see a repro. Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4

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

Similar topics

5
2187
by: Jason Butera | last post by:
I know that I can read/write custom properties of an object by using the following: Setting: document.all.customProp = "this"; Getting: document.all.customProp; Is there a way I can run code when this custom property is set. Or perhaps there is a way to create a custom method?
19
2968
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
2
3896
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I did some work on was having the control implement the IValidator interface and basically recreating...
1
1692
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar public properties of a custom Control neatly tied together -- rather than all over the IDE. One such set of values that will rarely be changed, so should have little priority in the IDE Properties panel, and therefore a good candidate for
10
1373
by: everett | last post by:
I am dynamically creating labels. I would like to be able to attach custom properties(?) to the labels so that I can query the property for the data in it later. Is this possible, and how do I start? thnx Ev
2
2431
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I am doing it wrong, any ideas what it is? Thanks in advance
0
3249
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design time. If I type the code in the aspx manually it does get parsed correctly though. This is an example of the aspx code that gets parsed correctly. For some reason, if I changed update the Tab property of the control through the GUI at design...
14
14623
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control so I get the ObjectDataSource. No problem ..... ObjectDataSource src = .... //is ok i have it
11
18100
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with ListView columns so it should be doable, thanks
6
11064
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
0
7947
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
7880
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6665
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5413
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.