Why this error message?

Discussion in 'ASP .Net' started by pvong, Aug 12, 2007.

  1. pvong

    pvong Guest

    VB.NET / ASP.NET

    I have a simple test. One simple Formview connected to a datasource. I
    have Button1 outside of the Formview. The Formview starts in ReadOnlyMode.
    All I want to do is on the button click, change the formview to Insert mode
    and then put the current date in the date textbox. The date textbox ID is
    DateTextBox and I've double check that to make sure it's right. Here's my
    simple code.

    Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
    System.EventArgs)

    FormView1.ChangeMode(FormViewMode.Insert)

    Dim datetb As TextBox = FormView1.FindControl("DateTextBox")

    datetb.Text = Now.Date.ToShortDateString()

    End Sub


    This is the error message I'm getting.

    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.

    Source Error:

    Line 6: FormView1.ChangeMode(FormViewMode.Insert)
    Line 7: Dim datetb As TextBox =
    FormView1.FindControl("DateTextBox")
    Line 8: datetb.Text = Now.Date.ToShortDateString()
    Line 9: End Sub
    Line 10: </script>


    Thanks in advance!
    Phil
    pvong, Aug 12, 2007
    #1
    1. Advertising

  2. On Aug 12, 4:49 pm, "pvong" <phillip*at*yahoo*dot*com> wrote:
    > VB.NET / ASP.NET
    >
    > I have a simple test. One simple Formview connected to a datasource. I
    > have Button1 outside of the Formview. The Formview starts in ReadOnlyMode.
    > All I want to do is on the button click, change the formview to Insert mode
    > and then put the current date in the date textbox. The date textbox ID is
    > DateTextBox and I've double check that to make sure it's right. Here's my
    > simple code.
    >
    > Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
    > System.EventArgs)
    >
    > FormView1.ChangeMode(FormViewMode.Insert)
    >
    > Dim datetb As TextBox = FormView1.FindControl("DateTextBox")
    >
    > datetb.Text = Now.Date.ToShortDateString()
    >
    > End Sub
    >
    > This is the error message I'm getting.
    >
    > 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.
    >
    > Source Error:
    >
    > Line 6: FormView1.ChangeMode(FormViewMode.Insert)
    > Line 7: Dim datetb As TextBox =
    > FormView1.FindControl("DateTextBox")
    > Line 8: datetb.Text = Now.Date.ToShortDateString()
    > Line 9: End Sub
    > Line 10: </script>
    >
    > Thanks in advance!
    > Phil


    Hi Phil

    Are there any entry in the datasource?
    Alexey Smirnov, Aug 12, 2007
    #2
    1. Advertising

  3. pvong

    pvong Guest

    Yes, there are entries in the Datasource. If I manually put the date in, it
    works perfectly. I just want when the user clicks this button for the
    formview to auto switch to Insert mode and auto put in today's date for them
    in the datetb.
    Thanks!
    Phil


    "Alexey Smirnov" <> wrote in message
    news:...
    > On Aug 12, 4:49 pm, "pvong" <phillip*at*yahoo*dot*com> wrote:
    >> VB.NET / ASP.NET
    >>
    >> I have a simple test. One simple Formview connected to a datasource. I
    >> have Button1 outside of the Formview. The Formview starts in
    >> ReadOnlyMode.
    >> All I want to do is on the button click, change the formview to Insert
    >> mode
    >> and then put the current date in the date textbox. The date textbox ID
    >> is
    >> DateTextBox and I've double check that to make sure it's right. Here's
    >> my
    >> simple code.
    >>
    >> Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As
    >> System.EventArgs)
    >>
    >> FormView1.ChangeMode(FormViewMode.Insert)
    >>
    >> Dim datetb As TextBox = FormView1.FindControl("DateTextBox")
    >>
    >> datetb.Text = Now.Date.ToShortDateString()
    >>
    >> End Sub
    >>
    >> This is the error message I'm getting.
    >>
    >> 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.
    >>
    >> Source Error:
    >>
    >> Line 6: FormView1.ChangeMode(FormViewMode.Insert)
    >> Line 7: Dim datetb As TextBox =
    >> FormView1.FindControl("DateTextBox")
    >> Line 8: datetb.Text = Now.Date.ToShortDateString()
    >> Line 9: End Sub
    >> Line 10: </script>
    >>
    >> Thanks in advance!
    >> Phil

    >
    > Hi Phil
    >
    > Are there any entry in the datasource?
    >
    pvong, Aug 12, 2007
    #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. Sara
    Replies:
    2
    Views:
    281
  2. tshad
    Replies:
    0
    Views:
    794
    tshad
    Jan 27, 2005
  3. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    6
    Views:
    5,492
    Kevin Spencer
    Aug 18, 2005
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    878
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,840
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page