469,631 Members | 1,579 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Property. What am I doing wrong? Going crazy ...

Hello,

I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:

' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation

Validation is class with various properties under the namespace
MyNameSpace:

' Validation
Public Class Validation

' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired

..............

End Class

I am using my control in a page as follows:

Dim a As New MyControl

MyControl.Property1 = "Something"

MyControl.Property2 = True

It works!

When I add the following property:

MyControl.Validation.IsRequired = False

I get the following error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

On code line:
MyControl.Validation.IsRequired = False

What am I doing wrong?

Thanks,

Miguel

Oct 31 '07 #1
10 1142
Validation Class instantiated how?
"shapper" <md*****@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
Hello,

I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:

' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation

Validation is class with various properties under the namespace
MyNameSpace:

' Validation
Public Class Validation

' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired

..............

End Class

I am using my control in a page as follows:

Dim a As New MyControl

MyControl.Property1 = "Something"

MyControl.Property2 = True

It works!

When I add the following property:

MyControl.Validation.IsRequired = False

I get the following error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

On code line:
MyControl.Validation.IsRequired = False

What am I doing wrong?

Thanks,

Miguel

Oct 31 '07 #2
On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:
Validation Class instantiated how?

"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@o80g2000hse.googlegr oups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel
Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...

MyControl.Validation = val

Is this what you mean?

I am not doing this.

Do I need to do this?

But can't I declare a property of type class and then define it?

Thanks,
Miguel

Oct 31 '07 #3
On Oct 31, 2:44 am, shapper <mdmo...@gmail.comwrote:
On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:


Validation Class instantiated how?
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel

Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...

MyControl.Validation = val

Is this what you mean?

I am not doing this.

Do I need to do this?

But can't I declare a property of type class and then define it?

Thanks,
Miguel- Hide quoted text -

- Show quoted text -
Miguel, he means that Validation Class is null and this is the reason
why you got "object reference not set to an instance of an object".
You need to have something like this

Private _Validation As Validation = New Validation

Oct 31 '07 #4
On Oct 31, 8:33 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Oct 31, 2:44 am, shapper <mdmo...@gmail.comwrote:
On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:
Validation Class instantiated how?
"shapper" <mdmo...@gmail.comwrote in message
>news:11**********************@o80g2000hse.googleg roups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel
Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...
MyControl.Validation = val
Is this what you mean?
I am not doing this.
Do I need to do this?
But can't I declare a property of type class and then define it?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -

Miguel, he means that Validation Class is null and this is the reason
why you got "object reference not set to an instance of an object".
You need to have something like this

Private _Validation As Validation = New Validation
Bah, it is not the first time that this happens to my.
I copy paste a property from another another which is of type string
and I miss the New.

I wonder if Microsoft is going to implement the following features in
VB.NET as there is in C# in .NET Framework 3.5?
Does anyone knows?

Thanks,
Miguel

Oct 31 '07 #5
On Oct 31, 11:52 am, shapper <mdmo...@gmail.comwrote:
On Oct 31, 8:33 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:


On Oct 31, 2:44 am, shapper <mdmo...@gmail.comwrote:
On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:
Validation Class instantiated how?
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel
Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...
MyControl.Validation = val
Is this what you mean?
I am not doing this.
Do I need to do this?
But can't I declare a property of type class and then define it?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Miguel, he means that Validation Class is null and this is the reason
why you got "object reference not set to an instance of an object".
You need to have something like this
Private _Validation As Validation = New Validation

Bah, it is not the first time that this happens to my.
I copy paste a property from another another which is of type string
and I miss the New.

I wonder if Microsoft is going to implement the following features in
VB.NET as there is in C# in .NET Framework 3.5?
Does anyone knows?

Thanks,
Miguel- Hide quoted text -

- Show quoted text -
What features?

When you declared Shared class or method then you would not need to
create a New instance of a class/method. It's up to you and depends on
design

Oct 31 '07 #6
On Oct 31, 11:22 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Oct 31, 11:52 am, shapper <mdmo...@gmail.comwrote:
On Oct 31, 8:33 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Oct 31, 2:44 am, shapper <mdmo...@gmail.comwrote:
On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:
Validation Class instantiated how?
"shapper" <mdmo...@gmail.comwrote in message
>news:11**********************@o80g2000hse.googleg roups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel
Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...
MyControl.Validation = val
Is this what you mean?
I am not doing this.
Do I need to do this?
But can't I declare a property of type class and then define it?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
Miguel, he means that Validation Class is null and this is the reason
why you got "object reference not set to an instance of an object".
You need to have something like this
Private _Validation As Validation = New Validation
Bah, it is not the first time that this happens to my.
I copy paste a property from another another which is of type string
and I miss the New.
I wonder if Microsoft is going to implement the following features in
VB.NET as there is in C# in .NET Framework 3.5?
Does anyone knows?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -

What features?

When you declared Shared class or method then you would not need to
create a New instance of a class/method. It's up to you and depends on
design
Oops, didn't post the link (Automatic Properties):
http://weblogs.asp.net/scottgu/archi...tializers.aspx

Thanks,
Miguel

Oct 31 '07 #7
On Oct 31, 12:37 pm, shapper <mdmo...@gmail.comwrote:
Oops, didn't post the link (Automatic Properties):http://weblogs.asp.net/scottgu/archi...-orcas-languag...
Not in the same way. In C# 3.5 you could use "unassigned" properties
like here

Person p = new Person();
p.FirstName = "Miguel";
Console.Write(p.FirstName); // "Miguel"

In VB.NET such construction would give you an empty string.

But unlike C# you can use "unassigned" GET properties in .NET 2, e.g.

Public Class Person

Public Property FirstName() As String
Get
End Get
Set(ByVal value As String)
End Set
End Property
....
End Class

would work without any problem. And in C# you cannot do it.

BTW, you can get Orcas Beta 2 and test all new things by yourself
http://msdn2.microsoft.com/vstudio/aa700831.aspx

Oct 31 '07 #8
On Oct 31, 12:31 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Oct 31, 12:37 pm, shapper <mdmo...@gmail.comwrote:
Oops, didn't post the link (Automatic Properties):http://weblogs.asp.net/scottgu/archi...-orcas-languag...

Not in the same way. In C# 3.5 you could use "unassigned" properties
like here

Person p = new Person();
p.FirstName = "Miguel";
Console.Write(p.FirstName); // "Miguel"

In VB.NET such construction would give you an empty string.

But unlike C# you can use "unassigned" GET properties in .NET 2, e.g.

Public Class Person

Public Property FirstName() As String
Get
End Get
Set(ByVal value As String)
End Set
End Property
...
End Class

would work without any problem. And in C# you cannot do it.

BTW, you can get Orcas Beta 2 and test all new things by yourselfhttp://msdn2.microsoft.com/vstudio/aa700831.aspx
Thanks Alexey,
Miguel

Oct 31 '07 #9
Why not instantiate the variabele with the definition, in c# i would
do something like:

private Validation _validation = new Validation();

It probably would be something like this in VB.Net:

Private _Validation as new Validation

That way you would always have a valid object instance....

Greets.
On Tue, 30 Oct 2007 18:44:37 -0700, shapper <md*****@gmail.comwrote:
>On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:
>Validation Class instantiated how?

"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@o80g2000hse.googleg roups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel

Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...

MyControl.Validation = val

Is this what you mean?

I am not doing this.

Do I need to do this?

But can't I declare a property of type class and then define it?

Thanks,
Miguel
Nov 2 '07 #10
On Nov 2, 7:56 pm, John MJ Gorter <john.gor...@gmail.comwrote:
Why not instantiate the variabele with the definition, in c# i would
do something like:

private Validation _validation = new Validation();

It probably would be something like this in VB.Net:

Private _Validation as new Validation

That way you would always have a valid object instance....

Greets.

On Tue, 30 Oct 2007 18:44:37 -0700, shapper <mdmo...@gmail.comwrote:
On Oct 31, 12:40 am, "IfThenElse" <sql_agent...@hotmail.comwrote:
Validation Class instantiated how?
"shapper" <mdmo...@gmail.comwrote in message
>news:11**********************@o80g2000hse.googleg roups.com...
Hello,
I have a custom control under namespace MyNameSpace.WebControls with a
property of type validation:
' Validation
Private _Validation As Validation
< _
Bindable(True), _
Category("Behavior"), _
DefaultValue(""), _
Localizable(True) _
_
Public Property Validation() As Validation
Get
Return _Validation
End Get
Set(ByVal value As Validation)
_Validation = value
End Set
End Property ' Validation
Validation is class with various properties under the namespace
MyNameSpace:
' Validation
Public Class Validation
' IsRequired
Private _IsRequired As Boolean
Public Property IsRequired() As Boolean
Get
If _IsRequired = Nothing Then
_IsRequired = False
End If
Return _IsRequired
End Get
Set(ByVal value As Boolean)
_IsRequired = value
End Set
End Property ' IsRequired
..............
End Class
I am using my control in a page as follows:
Dim a As New MyControl
MyControl.Property1 = "Something"
MyControl.Property2 = True
It works!
When I add the following property:
MyControl.Validation.IsRequired = False
I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
On code line:
MyControl.Validation.IsRequired = False
What am I doing wrong?
Thanks,
Miguel
Well, I am not using something in my code as follows:
Dim val As New Validation
val.IsRequired = True
val. ...
MyControl.Validation = val
Is this what you mean?
I am not doing this.
Do I need to do this?
But can't I declare a property of type class and then define it?
Thanks,
Miguel- Hide quoted text -

- Show quoted text -
we already found it some days ago

Nov 3 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

27 posts views Thread by sklett | last post: by
8 posts views Thread by AMDRIT | last post: by
9 posts views Thread by Tony Girgenti | last post: by
1 post views Thread by shapper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.