Object reference not set for an instance of an object in a .ASCX file

  • Thread starter Thread starter Cal Who
  • Start date Start date
C

Cal Who

In Design mode the code below shows:
Error rendering control - dp1
An unhandled exception has occurred.
Object reference not set for an instance of an object.

Likewise for tp1, dp2 and tp2

The code appears to work OK but I would like to remove those notices when I
look at it.

Any suggestions?

Thanks



<%@ Control Language="VB" AutoEventWireup="false"
CodeFile="DurationSelecter.ascx.vb" Inherits="Calendar_DurationSelecter" %>

<%@ Register TagPrefix="MyLib" Namespace="My.Library" %>

<script runat="server">


Public Property startDateTime() As Date

Get

Return dp1.SelectedDate.Add(tp1.SelectedTime.TimeOfDay)


End Get

Set(ByVal value As Date)

dp1.SelectedDate = value

tp1.SelectedTime = value

End Set

End Property


Public Property endDateTime() As Date

Get

Return dp2.SelectedDate.Add(tp2.SelectedTime.TimeOfDay)


End Get

Set(ByVal value As Date)

dp2.SelectedDate = value

tp2.SelectedTime = value

End Set

End Property


</script>

<table>

<tr>

<td align="center" colspan="2">

Start Date and Time:

</td>

<td align="center" colspan="2">

End Date and Time:

</td>

</tr>

<tr>

<td>

<MyLib:DatePicker ID="dp1" runat="server" />

</td>

<td>

<MyLib:TimePicker ID="tp1" runat="server" />

</td>

<td>

<MyLib:DatePicker ID="dp2" runat="server" />

</td>

<td>

<MyLib:TimePicker ID="tp2" runat="server" />

</td>

</tr>

</table>



the .vb file contains only:

Partial Class Calendar_DurationSelecter

Inherits System.Web.UI.UserControl

End Class
 
Cal Who said:
In Design mode the code below shows:
Error rendering control - dp1
An unhandled exception has occurred.
Object reference not set for an instance of an object.

Likewise for tp1, dp2 and tp2

The code appears to work OK but I would like to remove those notices when I
look at it.

Any suggestions?

I would suspect that one of your data values is a null value. A value cannot
be cast to an object like string, int, longm, etc if the value is null.

Your application is failing, and it's going on like nothing happened due to
the application not knowing that it failed.
 
Back
Top