PDA

View Full Version : null exception Object reference....


gtjr92
04-19-2005, 06:01 PM
:cry:
I keep getting the below error on my page. I have got it to work if the session is not null. I actually got lucky when that happened, I had a session open on the page i was editing so when I refreshed the page it kept the session and passed my varible to my label.
So what I believe is happening is that because my label is null when the page first loads it is calling this error. O could be wrong if someone could look at my code that would be great thanks. I am new to sessions etc. I do think the real issue could be that the list box does not have a default value when the page loads. I am not sure how to correct that.
Thanks.

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 34: <tr>
Line 35: <th scope="row">sess WK ID </th>
Line 36: <td><asp:Label ID="Label1" Text="<%#WeeksLBX.SelectedItem.Value%>" runat="server" /> </td>
Line 37: </tr>
Line 38: </ContentsTemplate>
Source File: C:\Inetpub\wwwroot\gbc_ti2\set_Sess2bk.aspx Line: 36
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP.set_Sess2bk_aspx.__DataBindLabel1(Object sender, EventArgs e) in C:\Inetpub\wwwroot\gbc_ti2\set_Sess2bk.aspx:36
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.Control.DataBind() +86
DreamweaverCtrls.PageBind.Page_Load(Object src, EventArgs E)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +750






<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="DSWeeks2"
runat="Server"
IsStoredProcedure="false"
If not is postback then
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_GBCTITHE") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_GBCTITHE") %>'
CommandText='<%# "SELECT * FROM Weeks ORDER BY WKID ASC" %>'
Debug="true"
></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<script language="vb" runat="server">
Sub SetSessionVariable_Click(ByVal s As Object, ByVal e As EventArgs)
Session("SessWKID")= Request("WeeksLBX.SelectedItem.Value")
Response.Redirect("gbcTithe_TS3.aspx")
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Set Sess</title>
</head>
<body>
<form name="form1" method="post" action="" runat="server">
<table width="50%" border="0" cellspacing="1" cellpadding="1">
<caption>
sess
</caption>

<ContentsTemplate>
<tr>
<th scope="row">sess WK ID </th>
<td><asp:Label ID="Label1" Text="<%#WeeksLBX.SelectedItem.Value%>" runat="server" /> </td>
</tr>
</ContentsTemplate>

<tr>
<th scope="row">Sess 2 </th>
<td><asp:TextBox ID="Sess2" runat="server" /></td>
</tr>
<tr>
<th scope="row"> </th>
<td><asp:Button ID="SessBtn" Text="Submit" runat="server" onClick="SetSessionVariable_Click"/></td>
</tr>
<asp:ListBox Height="300px" Width="100px" Backcolor="DarkGray"
ForeColor="DarkGreen" Rows="30" ID="WeeksLBX" DataTextFormatString="{0:d}" AutoPostBack="false"
DataSource=<%# DSWeeks2.DefaultView %> DataTextField="Date" DataValueField="Wkid" OnSelectedIndexChanged="SetSessionVariable_Click"
runat="server" > </asp:ListBox>

</table>
</form>
</body>
</html>