Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: page_load help


Message #1 by Greg Partin <GPartin@c...> on Mon, 15 Apr 2002 11:55:51 -0400
Hi folks,

I'm having some problems with the page_load function.  Here is my code:

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim myReader As SqlDataReader
        Dim SQL As String
        Dim ConnStr As String

        ConnStr = "server=SQL-LAB1;database=TLO;UID=user;PWD=password"
        SQL = "SELECT test_id, user_name FROM Users"
        myConnection = New SqlConnection(ConnStr)
        myConnection.Open()
        myCommand = New SqlCommand(SQL, myConnection)
        myReader = myCommand.ExecuteReader()

        dgrResult.DataSource = myReader
        dgrResult.DataBind()
        myConnection.Close()
        myConnection = Nothing
     
End Sub

This code works perfectly if I place it in a function for an onclick event,
but bombs when I put it in the Page_Load event.  Is there something obvious
about the page_load event that would prevent this code from working?

thanks in advance,
Greg

Message #2 by Greg Partin <GPartin@c...> on Mon, 15 Apr 2002 12:02:42 -0400
By the way, the error message I am getting is:

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

thanks,
Greg

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...]
Sent: Monday, April 15, 2002 11:56 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] page_load help


Hi folks,

I'm having some problems with the page_load function.  Here is my code:

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim myReader As SqlDataReader
        Dim SQL As String
        Dim ConnStr As String

        ConnStr = "server=SQL-LAB1;database=TLO;UID=user;PWD=password"
        SQL = "SELECT test_id, user_name FROM Users"
        myConnection = New SqlConnection(ConnStr)
        myConnection.Open()
        myCommand = New SqlCommand(SQL, myConnection)
        myReader = myCommand.ExecuteReader()

        dgrResult.DataSource = myReader
        dgrResult.DataBind()
        myConnection.Close()
        myConnection = Nothing
     
End Sub

This code works perfectly if I place it in a function for an onclick event,
but bombs when I put it in the Page_Load event.  Is there something obvious
about the page_load event that would prevent this code from working?

thanks in advance,
Greg



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
 
Message #3 by "Minh T. Nguyen" <nguyentriminh@y...> on Mon, 15 Apr 2002 09:14:55 -0700
Greg,

	Tell us on which line you get the NullReferenceException. Then
you can pinpoint which object you are trying to use that you have not
instantiated yet.

Minh.

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...] 
Sent: Monday, April 15, 2002 9:03 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


By the way, the error message I am getting is:

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

thanks,
Greg

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...]
Sent: Monday, April 15, 2002 11:56 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] page_load help


Hi folks,

I'm having some problems with the page_load function.  Here is my code:

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim myReader As SqlDataReader
        Dim SQL As String
        Dim ConnStr As String

        ConnStr = "server=SQL-LAB1;database=TLO;UID=user;PWD=password"
        SQL = "SELECT test_id, user_name FROM Users"
        myConnection = New SqlConnection(ConnStr)
        myConnection.Open()
        myCommand = New SqlCommand(SQL, myConnection)
        myReader = myCommand.ExecuteReader()

        dgrResult.DataSource = myReader
        dgrResult.DataBind()
        myConnection.Close()
        myConnection = Nothing
     
End Sub

This code works perfectly if I place it in a function for an onclick
event,
but bombs when I put it in the Page_Load event.  Is there something
obvious
about the page_load event that would prevent this code from working?

thanks in advance,
Greg

Message #4 by Greg Partin <GPartin@c...> on Mon, 15 Apr 2002 13:00:35 -0400
The line that bombs is the following:

dgrResult.DataBind()

I also have the following code in my page behind.

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports BeginningTests.SubjectDropDown
Imports BeginningTests.ClassDropDown
Imports BeginningTests.ScoreFilter
Imports System.Reflection
Imports System.Web.UI.WebControls.DataGridItemEventArgs
Imports System.Object
Imports System.Data.DataTable

Public Class ClassProgressReport
    Inherits System.Web.UI.Page
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents lblReportName As System.Web.UI.WebControls.Label
    Protected WithEvents txtReportName As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnSaveReport As System.Web.UI.WebControls.Button
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents dgrResult As System.Web.UI.WebControls.DataGrid
    Protected WithEvents hdnUserId As System.Web.UI.WebControls.Label
    Public WithEvents lblnumtaken As System.Web.UI.WebControls.Label
    Protected WithEvents txtMsg As System.Web.UI.WebControls.Label
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label

thanks,
Greg


-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: Monday, April 15, 2002 12:15 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


Greg,

	Tell us on which line you get the NullReferenceException. Then
you can pinpoint which object you are trying to use that you have not
instantiated yet.

Minh.

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...] 
Sent: Monday, April 15, 2002 9:03 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


By the way, the error message I am getting is:

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

thanks,
Greg

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...]
Sent: Monday, April 15, 2002 11:56 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] page_load help


Hi folks,

I'm having some problems with the page_load function.  Here is my code:

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim myReader As SqlDataReader
        Dim SQL As String
        Dim ConnStr As String

        ConnStr = "server=SQL-LAB1;database=TLO;UID=user;PWD=password"
        SQL = "SELECT test_id, user_name FROM Users"
        myConnection = New SqlConnection(ConnStr)
        myConnection.Open()
        myCommand = New SqlCommand(SQL, myConnection)
        myReader = myCommand.ExecuteReader()

        dgrResult.DataSource = myReader
        dgrResult.DataBind()
        myConnection.Close()
        myConnection = Nothing
     
End Sub

This code works perfectly if I place it in a function for an onclick
event,
but bombs when I put it in the Page_Load event.  Is there something
obvious
about the page_load event that would prevent this code from working?

thanks in advance,
Greg



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
 
Message #5 by "Minh T. Nguyen" <nguyentriminh@y...> on Mon, 15 Apr 2002 10:02:02 -0700
Greg,

	And you made sure that your datagrid also exists on the HTML
side of the ASPX file? With the correct name and casing? It happened to
me before that VS.NET does not change the code behind if I change the
name of my control on the HTML side.

Good luck,
Minh.

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...] 
Sent: Monday, April 15, 2002 10:01 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


The line that bombs is the following:

dgrResult.DataBind()

I also have the following code in my page behind.

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports BeginningTests.SubjectDropDown
Imports BeginningTests.ClassDropDown
Imports BeginningTests.ScoreFilter
Imports System.Reflection
Imports System.Web.UI.WebControls.DataGridItemEventArgs
Imports System.Object
Imports System.Data.DataTable

Public Class ClassProgressReport
    Inherits System.Web.UI.Page
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents lblReportName As
System.Web.UI.WebControls.Label
    Protected WithEvents txtReportName As
System.Web.UI.WebControls.TextBox
    Protected WithEvents btnSaveReport As
System.Web.UI.WebControls.Button
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents dgrResult As System.Web.UI.WebControls.DataGrid
    Protected WithEvents hdnUserId As System.Web.UI.WebControls.Label
    Public WithEvents lblnumtaken As System.Web.UI.WebControls.Label
    Protected WithEvents txtMsg As System.Web.UI.WebControls.Label
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label

thanks,
Greg


-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: Monday, April 15, 2002 12:15 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


Greg,

	Tell us on which line you get the NullReferenceException. Then
you can pinpoint which object you are trying to use that you have not
instantiated yet.

Minh.

Message #6 by Greg Partin <GPartin@c...> on Mon, 15 Apr 2002 13:15:48 -0400
Minh,

Yes...it exists with the correct name and everything.  The thing I don't get
is that this code runs fine if I put it into an onclick event.  It just
doesn't seem to work on page_load.  I copied and pasted the exact same code
from the onclick event to the page_load....I just don't get it.

thanks for your input,
Greg

-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: Monday, April 15, 2002 1:02 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


Greg,

	And you made sure that your datagrid also exists on the HTML
side of the ASPX file? With the correct name and casing? It happened to
me before that VS.NET does not change the code behind if I change the
name of my control on the HTML side.

Good luck,
Minh.

-----Original Message-----
From: Greg Partin [mailto:GPartin@c...] 
Sent: Monday, April 15, 2002 10:01 AM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


The line that bombs is the following:

dgrResult.DataBind()

I also have the following code in my page behind.

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports BeginningTests.SubjectDropDown
Imports BeginningTests.ClassDropDown
Imports BeginningTests.ScoreFilter
Imports System.Reflection
Imports System.Web.UI.WebControls.DataGridItemEventArgs
Imports System.Object
Imports System.Data.DataTable

Public Class ClassProgressReport
    Inherits System.Web.UI.Page
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents lblReportName As
System.Web.UI.WebControls.Label
    Protected WithEvents txtReportName As
System.Web.UI.WebControls.TextBox
    Protected WithEvents btnSaveReport As
System.Web.UI.WebControls.Button
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents dgrResult As System.Web.UI.WebControls.DataGrid
    Protected WithEvents hdnUserId As System.Web.UI.WebControls.Label
    Public WithEvents lblnumtaken As System.Web.UI.WebControls.Label
    Protected WithEvents txtMsg As System.Web.UI.WebControls.Label
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label

thanks,
Greg


-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: Monday, April 15, 2002 12:15 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] RE: page_load help


Greg,

	Tell us on which line you get the NullReferenceException. Then
you can pinpoint which object you are trying to use that you have not
instantiated yet.

Minh.



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
 

  Return to Index