Hi diane!
Code for the first Page-
Code within the Aspx Page
//-------------------------------------------------------------------
<%@ Page Language="
VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public ReadOnly Property pp_TextBox1() As TextBox
Get
Return TextBox1
End Get
End Property
Public ReadOnly Property pp_Calendar1() As Calendar
Get
Return Calendar1
End Get
End Property
' this Concept called Properties
'The above code creates an,let's call them - "instances" of a original objects.
'Another words by creating these ReadOnly properties you will able
'To work with this 2 objects from another page.
'For example: If you going to use a pp_TextBox1 property in the Second page,
'the pp_TextBox will basically equals to the TextBox1 of the first page.
'You might think of the pp_TextBox1 like of some kind of a bridge, that connects
'to the Physical TextBox1 in the first Page.
'The truth is, this concept is a really basics of a programming of
VB and of C#
'This means that whenever we want to modify these controls later in the code, or
'in another page like in Asp.net 2.0 we need to set up the PROPERTIES of these controls,
'Otherwise these controls will be unreachable (In some cases)
'Why we are using pp_? we could use any word we want.
'pp_ means PreviousPage... So, by typing pp_TextBox1 in the second page you will clearly understand that
'we are going to work with the PreviousPageTextBox. Very Simple!
'Now, do not let the code to confuse you.
'The below Button_Click Event means this:
'When you Click the button, the Page is going to PostBack Information to It-Self.
'He gonna show you Hello + text that you typed in
'theTextBox1,and he will show you your selected Date from the calendar.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "Hello " & TextBox1.Text & "<br />" & "Date Selected: " & Calendar1.SelectedDate.ToShortDateString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
VB Page1</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter your Name:<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Please Enter your name"></asp:RequiredFieldValidator><br />
<br />
Please select Date.<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit Page to itself" OnClick ="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Submit to Page 2" PostBackUrl ="~/2.aspx" /><br />
<br />
<a href="2.aspx">Go Directly to the Page 2</a></div>
</form>
</body>
</html>
---------------------------------------------------------------------------
this is Second Page
<%@ Page Language="
VB" %>
<%@ PreviousPageType VirtualPath ="~/1.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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() & "<br />" & "*You have reached the Second Page."
Else
Response.Redirect("1.aspx")
End If
Catch ex As System.NullReferenceException
Response.Redirect("1.aspx")
End Try
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>This is Page 2</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
<br />
<a href="1.aspx">Back</a></div>
</form>
</body>
</html>
*******************************************
Copy this code and have fun :)
hope this will help.
Good luck!