We have many number of options to pass values from one page to the other page. This is also one of them. Here we can access one form controls values in the other pages after submitting the form.



If the source page uses the "HTTP POST" action to navigate to the target page, then we can retrieve posted values from the "Form" collection in the target page.

Here we need to remember one thing., that we can get only the post values; we cannot read the values of arbitrary controls on the page.

Lets take some controls in the source page, like HTML elements (such as input or text-area) or ASP.NET server controls (such as TextBox or DropDownList controls) that post values when the form is submitted.

In the target page, read the "Form" collection, which returns a dictionary of name/value pairs, one pair for each posted value.

void Page_Load(object sender, EventArgs e)
{
string Values = "";
System.Collections.Specialized.NameValueCollection postedData = Request.Form;
String nextKey;
for(int i = 0; i < postedData.AllKeys.Length; i++)
    {
        nextKey = postedData.AllKeys[i];
        if(nextKey.Substring(0, 2) != "__")
        {
Values += nextKey +" = "+postedData[i];
}
}
Label1.Text = Values.ToString();
}

Post information from an ASP.NET Web pages includes the values of hidden fields, such as __VIEWSTATE, __EVENTTARGET, and __EVENTARGUMENT, which are used for internal processing in the page.

We had some more process to pass values from one page to other page.
Lets discuss those in next post.


See you again.

Share it

1 comments:

  • Anonymous said... June 8, 2011 at 11:43 AM

    Hi, am a beginner in asp.net, nice and useful article but it would be very clear if u explain the above code along with the source page..
    Thanking you,

Post a Comment