Has just started a little bit with exercises in the book and has encountered a problem already in the beginning, Listing 1-13. I always get a following error when I try to go directly to page2.aspx and not go through page1.aspx. System.NullReferenceException: Object reference not set to an instance of an object. It somplains on line 5 in my codebehind: "If Not PreviousPage Is Nothing And PreviousPage.IsCrossPagePostBack Then"
This is how my code behind on page2.aspx.
vb looks like:
Public Partial Class Page2
Inherits System.Web.UI.Page
Private Sub Page2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not PreviousPage Is Nothing And PreviousPage.IsCrossPagePostBack Then
Dim pp_Textbox1 As TextBox
Dim pp_Calendar1 As Calendar
pp_Textbox1 = CType(PreviousPage.FindControl("Textbox1"), TextBox)
pp_Calendar1 = CType(PreviousPage.FindControl("Calender1"), Calendar)
Label1.Text = "Hello " & pp_Textbox1.Text & "<br /> Date Selected: " & pp_Calendar1.SelectedDate.ToShortDateString()
Else
Response.Redirect("Page1.aspx")
End If
End Sub
End Class
and this is my page2.aspx
<%@ Page Language="
vb" AutoEventWireup="false" CodeBehind="Page2.aspx.
vb" Inherits="ASPNET.Page2" %>
<%@ PreviousPageType VirtualPath="~/Page1.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Second Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>
http://www.workidoo.com