|
Subject:
|
[NullReferenceException: Object reference not set
|
|
Posted By:
|
creiche
|
Post Date:
|
9/21/2003 10:05:22 AM
|
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
|
|
Reply By:
|
planeswalk
|
Reply Date:
|
9/23/2003 1:32:17 AM
|
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 marlon@webburner.com www.webburner.com Toll-Free: 877-535-2876
|
|
Reply By:
|
creiche
|
Reply Date:
|
9/23/2003 5:53:13 AM
|
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
|
|
Reply By:
|
planoie
|
Reply Date:
|
9/23/2003 8:38:51 AM
|
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
|