Im trying to pass a value of a date control from form1 to form2.
on form 1.aspx.vb:
Public ReadOnly Property Property1() As Date
Get
Return StartDate.SelectedDate
End Get
End Property
On Form2.aspx:
<%@ PreviousPageType VirtualPath="~/form1.aspx" %>
On form2.aspx.vb:
Label14.Text = PreviousPage.Property1
when I run it, the compiler gives me an error:
"Object reference not set to an instance of an object."
with marking in red:
Label14.Text = PreviousPage.Property1
Tried to assign the property to a string, it did not work either.
Any suggestions ???
Regards.
When the Form2.aspx page is accessed directly without cross-page posting, then PreviousPage property is null. You should add this check before retrieving value of Property1:
Using PreviousPageType VirtualPath=”~/form1.aspx” directive is a little bit dangerous when other page than Form1.aspx do cross-page post to Form2. PreviousPage property throws InvalidCastException (it expects Form1 page but it gets something else).
For more information see: http://msdn.microsoft.com/en-us/library/ms178139.aspx.