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

Discussion in 'ASP .Net' started by Cal Who, Mar 30, 2010.

  1. Cal Who

    Cal Who Guest

    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, Mar 30, 2010
    #1
    1. Advertising

  2. Cal Who

    Mr. Arnold Guest

    RE: Object reference not set for an instance of an object in a .ASCX f

    "Cal Who" wrote:

    > 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.
     
    Mr. Arnold, Apr 1, 2010
    #2
    1. Advertising

  3. Cal Who

    Cal Who Guest

    Re: Object reference not set for an instance of an object in a .ASCX f

    Right you are. I didn't know I had to do that.

    Thanks



    "Mr. Arnold" <> wrote in message
    news:...
    >
    >
    > "Cal Who" wrote:
    >
    >> 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.
     
    Cal Who, Apr 2, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parthiv Joshi
    Replies:
    2
    Views:
    716
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,423
    Anushi
    Jul 29, 2004
  3. Chris Fink
    Replies:
    2
    Views:
    4,139
    David Waz...
    Jul 3, 2003
  4. Alexander Widera

    sessions, ascx, reference not set to an instance

    Alexander Widera, May 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    551
    William F. Robertson, Jr.
    May 16, 2005
  5. Replies:
    1
    Views:
    514
    Mark Rae [MVP]
    Sep 20, 2007
Loading...

Share This Page