i'm taking my data from one page(Default.aspx) to another page(default2.aspx) on button1_Click(in default.aspx).
for that i have set the PostBackUrl of the Button1 to default2.aspx.
It is working fine.
But suppose if some one is directly trying to access default2.aspx without going through default.aspx then he should be redirected to default.aspx !!! For that i have done the following coding:-
---------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If PreviousPage.IsCrossPagePostBack Then
Label1.Text = "Hello " & PreviousPage.pp_Textbox1.Text _
& "<br/>" & "Date Selected: " &
PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String()
Else
Response.Redirect("Default2.aspx")
End If
----------------------------------------
After doing this i set default2.aspx as my start page and then build it.But then it gives me this kind of an error:---------------------------------------
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 11:
Line 12: If PreviousPage.IsCrossPagePostBack Then
Line 13: Label1.Text = "Hello " & PreviousPage.pp_Textbox1.Text & "<br/>" & _
Line 14: "Date Selected: " & PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String()
Source File: c:\inetpub\wwwroot\Examples\WebSite\Default2.aspx.
vb Line: 12
--------------------------------------------------------
it says that an object reference has not been set and shows the error on Line: 12, whereas this is the exact solution given in Wrox's Profesional Asp.net 2.0, Chapter 3, and Page 74(It was 'Page.IsCrossPagePostBack' but in errata it is corrected to 'PreviousPage.IsCrossPagePostBack')
!!! Please Help If SomeOne Knows This !!!