Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2003, 10:05 AM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to creiche
Default [NullReferenceException: Object reference not set

Can anyone tell me why I'm getting this error message? See code below followed by full error:

<%@ Page language="vb" Codebehind="demo.aspx.cs" AutoEventWireup="false" Inherits="spaw.spaw.samples.demo" ValidateRequest="false" %>
<%@ Register TagPrefix="spaw" TagName="Spaw" Src="../spaw/spaw.ascx" %>
<%@Import NameSpace = "System.Data" %>
<%@Import NameSpace = "System.Data.SqlClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<script language="VB" runat="server">

    sub Page_Load()
        if Page.IsPostback then

            Dim strSQL As String
            Dim strConnection As String
            Dim objConnection As New SqlConnection
            Dim objCommand As New SqlCommand
            Dim txtTitle As String
            Dim txtText As String
            Dim txtParent As String
            Dim txtPath As String

            Title.Text = txtTitle
            Spaw1.Text = txtText
            Parent.Text = txtParent
            Path.Text = txtPath

            strConnection = "server=localhost;database=celink;User ID=sa;Password=ecom1091"
            strSQL = "insert into tbl_articles Values ('"&(txtTitle)&"','"&(txtText)&"','"&(txtParent)&" ','"&(txtPath)&"');"

            objConnection = New SqlConnection(strConnection)
            objConnection.Open()
            objCommand = New SqlCommand(strSQL, objconnection)
            objCommand.ExecuteNonQuery()

        end if
    end sub
</script>


<html>
<head>
<title>CeLink Data Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<Form runat="server">
Article Title: <asp:textbox ID="Title" Text="replace" runat="server"/><br><br>
Parent Link: <asp:textbox ID="Parent" Text="replace" runat="server"/><br><br>
File Path: <asp:textbox ID="Path" Text="replace" runat="server"/><br><br>
                <spaw:Spaw id="Spaw1" Width="600px" Text="replace" runat="server"/><br><br>
                <input type="submit">
</Form>
</body>
</html>

error:

[NullReferenceException: Object reference not set to an instance of an object.]
   spaw.spaw.samples.demo.Page_Load(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


 
Old September 23rd, 2003, 01:32 AM
Authorized User
 
Join Date: Jun 2003
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

It looks like the error is in the source code for our 'spaw' user control. If you can show us the code, it would help us point where the error is. Also, try replacing all instances of '&' with '+' in the following line for string concatenation.

    strSQL = "insert into tbl_articles Values ('"&(txtTitle)&"','"&(txtText)&"','"&(txtParent)&" ','"&(txtPath)&"');"

Cheers!





Marlon Villarama
Support Team
Web Burner Hosting
[email protected]
www.webburner.com
Toll-Free: 877-535-2876
 
Old September 23rd, 2003, 05:53 AM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to creiche
Default

I got it to work... (through painstaking trial and error) I stripped everything from the Page directive to look like this:
<%@ Page ValidateRequest="false" Debug="true" %>
It didin't like one of the other commands in there. Not sure which one but I suspect it was one of the 2 that referenced spaw... Thanks for your help!

Clay

 
Old September 23rd, 2003, 08:38 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

creiche-

Here's a little @Page directive deconstruction for your benefit (descriptions borrowed from the MSDN "@ Page" article:

<%@ Page language="vb" Codebehind="demo.aspx.cs" AutoEventWireup="false" Inherits="spaw.spaw.samples.demo" ValidateRequest="false" %>

language="vb": Specifies the language used when compiling all inline rendering (<% %> and <%= %>) and code declaration blocks within the page. Values can represent any .NET-supported language, including Visual Basic, C#, or JScript .NET.

Codebehind="demo.aspx.cs": Specifies the name of the compiled file that contains the class associated with the page. This attribute is used by the Visual Studio .NET Web Forms designer. It tells the designer where to find the page class so that the designer can create an instance of it for you to work with at design time. For example, if you create a Web Forms page in Visual Studio called WebForm1, the designer will assign the Codebehind attribute the value of WebForm1.aspx.vb, for Visual Basic, or WebForm1.aspx.cs, for C#. This attribute is not used at run time.

AutoEventWireup="false": Indicates whether the page's events are autowired. (The MSDN description is kind of vague no? What this really means is that when this page is processed, ASP.Net will try to automatically wire up the Page object's "Load" event with a method in the code named "Page_Load".)

Inherits="spaw.spaw.samples.demo": Defines a code-behind class for the page to inherit. Can be any class derived from the Page class.

ValidateRequest="false": I couldn't find this in either documentation for 1.0 or 1.1. What is means however is that the framework will check posted data for malicious code. Basically, if you tried to post HTML looking data in a form you'd get an error without this set to false.


Most likely, the problem you are having is occuring with the Inherits statement. Seeing as you are working with inline code and you don't have a codebehind file there is no "spaw.spaw.samples.demo" class for this page to inherit from which is why you are seeing an error message without a line number or a direct reference to code.

Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
System.NullReferenceException: Object reference no HelpWanted ASP.NET 1.0 and 1.1 Basics 11 October 24th, 2006 04:50 PM
Object Reference not set to an instance of object srinivas_chakka ASP.NET 1.0 and 1.1 Professional 0 February 8th, 2006 11:56 AM
System.NullReferenceException: Object reference no nidy_online VS.NET 2002/2003 2 June 9th, 2004 09:17 PM
System.NullReferenceException: Object reference... nordestgaard All Other Wrox Books 4 January 7th, 2004 01:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.