Thursday, March 29, 2012

passing values from form to form

I was wondering if it is possible to pass values from one aspx page to another aspx page using properties?

I want to create a property on the 2nd aspx page lets say Name(), and pass in the values from the first aspx page. I know how to pass values like this to a user control, but is it possible to pass it to another aspx page?> I was wondering if it is possible to pass values from one aspx page to another aspx page using properties?

You can sort of do this, but not as directly as you're suggesting.

In your firstpage.aspx:

Public Sub Button_Click( sender As Object, e As EventArgs )
Session( "Name" ) = "Value from textbox, or wherever"
Response.Redirect( "secondpage.aspx" )
End Sub

Then, in your secondpage.aspx:

Private _name As String
Public Property Name As String
Get
Return _name
End Get
Set
_name = Value
End Set
End Property

Public Sub Page_Init( sender As Object, e As EventArgs )
Name = Session( "Name" )
End Sub

If that doesn't help, perhaps you can explain more fully what you're trying to do.
That's what I'm trying to do. I knew that I can use session variables, just wondering if there's any other way to accomplish this.
You can store information into the QueryString as well.
Well, you can't directly access the second Page's properties from the first page, no.

After all, the second Page is not instantiated until the first is destroyed. So there can be no direct messaging between them.

It is for this reason that session variables exist. So, for "form to form" communication, session variables are ideal.

You can also create a single form thatacts like more than one form. If you're trying to keep information "alive" during a certain series of tasks, this might be a better way to go.

0 comments:

Post a Comment