Passing Data one page to another page in ASP.NET?
Saturday, April 12th, 2008we can only retrieve the values of the web form objects using the Request object. But what if we need to retreive the entire object from a different aspx page. In Classic ASP, passing an entire object from one page to another was possible with the help of either Session Objects or Application Object or we need to implement a custom way to transfer objects between ASP
pages.
Assume that, we have a page called source.aspx with one textbox and a button. When we click on the button, we are going to invoke a different page called destination.aspx. Our aim is to retrieve the entire texbox object from the destination.aspx.
Content of source.aspx
<%@ Page Language=”vb” Classname=”Source” %>
<script language=”VB” runat=”server”>
Sub Transfer(sender As Object, e As EventArgs)
Server.Transfer(”destination.aspx”)
End Sub
Public ReadOnly Property GetFirstname() As String
Get
Return txtFirstName.Text
End Get
End Property
Public ReadOnly Property GetFirstnameObj() As System.Object
Get
Return txtFirstName
End Get
End Property
</script>
Content of Destination.aspx
<script language=”VB” runat=”server”>
Sub Page_Load(sender As Object, e As EventArgs)
Dim objSource As source
objSource = CType(context.Handler, source)
Response.Write(”First Name is : ” & objSource.GetFirstnameObj.text & ”
“)
Response.Write(”ForeColor is : “)
Response.Write(objSource.GetFirstnameObj.ForeColor)
Response.Write(”
BackColor is : “)
Response.Write(objSource.GetFirstnameObj.BackColor)
End Sub
</script>