dcostelloe Level: VB Guru
 Registered: 11-06-2002 Posts: 74
|
Passing Objects from page to page
Hi all,
Someone in another group asked me how to pass objects from page to page using vb.net and ASP.Net.
Here is the sample:
On the page sending the data add a property:
This example uses an ArrayList but you can use whatever you want.
Page1.aspx Code
=============
Declare Section
Private arList1 as ArrayList = New ArrayList
On Page_Load
===========
Add data to ArrayList
Dim x as Int32
for x = 0 to 10
arlist1.Add( "Sample" & x)
Next x
' Add this to Page1
Public ReadOnly Property ArListData() As ArrayList
Get
Return arList1
End Get
End Property
Page2.aspx
=========
This is the receiver Page
Declare Section
Private objPage As Page1
Private arrList as arraylist = new Arraylist()
Page_Load
========
If Not IsPostBack Then
objPage = CType(Context.Handler, Page1)
arrList = objPage.arList1
End If
In the HTML Section of Page2 add the following:
<%@ Reference Page="Page1.aspx"%>
The final part is to load page2 from Page1
This example Uses Button Click Event on page1.
Private Sub btnClick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClick.Click
' Load Page 2 Here
Server.Transfer("Page2.aspx", False)
End Sub
You can pass pretty much anything with a reasonable impact on your system.
You can also use the session variable with a impact to your web server and application.
____________________________
Life is but a merry go round
around and around :-)
Visit us today:
http://www.welford-costelloe.com
|