Hi,
if you want to pass "simple" values, you can put them in the query string for the URL of the destination page.
For example, if you want to pass the parameters "action" and "id" from Page1.aspx to Page2.aspx, you can do (from Page1):
Response.Redirect("Page2.aspx?action=view&id=1234");
The querystring starts with a question mark '?' and contains name-value pairs, each one separated by '&'
In Page2.aspx, you can access the querystring from the property Request.QueryString. You will obtain a NameValueCollection
that can be accessed also by index. For example:
string action = Request.QueryString["action"];
string id = Request.QueryString["id"];
If you want to pass anything to your destination page (i.e. objects), you can expose them through public properties in Page1.aspx.
Then, in Page2.aspx, you can retrieve the object representing your Page1 WebForm.
Let's suppose you want to access an ArrayList. In Page1.aspx codebehind, you'll have a public property:
public ArrayList Arr
{
get { return myArr;}
set { myArr = value;}
}
On Page1.aspx, you will request Page2.aspx with the statement:
Server.Transfer("Page2.aspx");
On Page2.aspx you can get the form that requested the page (e.g. Page1):
Page1 handler = (Page1)Context.Handler;
Then, you can access the public properties of the Page1 WebForm:
ArrayList arr = handler.Arr;
Alessandro Gallo |
Blog | My book: ASP.NET AJAX In Action