CrossPagePostBack VB Version
Hi there!
Maybe my code is not perfect, but it finally works! Thank God!
I figured out that,in some cases we can't use PreviousPage Property, because, if we will go directly to the second page, PreviousPage Property will equal to Nothing.You simply can't use PreviousPage Property that contains Null. That's why you get Error.
I tried everything, Logical Operators, like C# code of this example, but nothing helped me to fix this NullReference error.
So I became with the idea about System.NullReferenceException.
Something I learned from the C# Basics about Exceptions.
This is really good way to catch some unexpected errors.
It took me a Night, to understand how to put this all together.
In the beginning, I should fist understand, how to build a
VB version, because I don't familiar with
VB Syntax.
(Some things that works in C# not allways works in
VB.)
I took the original C# Idea of Handling Exceptions and wrote this in
VB.
Finally this crappy SecondPage, began redirecting us to the FirstPage without Null-error. Thanks to the
System.NullReferenceException :)
You can go directly to the Second page, and you'll be redirected.
You can post page to it self, and to the second page too.
Everything works fine.
Here's the code.
//--------------------------------------------------------------------
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Try
If PreviousPage.IsCrossPagePostBack Then
Label1.Text = "Hello " & PreviousPage.pp_TextBox1.Text & "<br />" & "Date Selected: " & PreviousPage.pp_Calendar1.SelectedDate.ToShortDate String()
Else
Response.Redirect("PageVb1.aspx")
End If
Catch ex As System.NullReferenceException
Response.Redirect("PageVb1.aspx")
End Try
End Sub
As i figured out, we can use PreviousPageProperty,only if previousPage equals to some value,but not a Null-Nothing. When PreviousPage equals to Nothing, PreviousePageProperty becomes Unreachable(He don't know what to do with the null).It's more like, if it gets a Null from the previousPage,
PreviousPageProperty says: Oops! I don't know how to work with Nulls. So we need something that can identify Our null, and to do something with it. This is: System.NullReferenceException.
He say's I see the Null, I'm redirecting you, because you are a good guy :)
</script>
//----------------------------------------------------------------
You can check the Working example on my site:
http://aspspider.info/chadfunk/Cross...ageVB/1vb.aspx