Thursday, March 13, 2008

Passing values between ASP.NET pages

Today I learned how to pass values between two pages in ASP.NET. Lets say you have Page1.aspx and Page2.aspx and want to pass values from Page1.aspx to Page2.aspx. You can put link button control on Page1.aspx and on its click event you can write this code

string mydata = "88";
Response.Redirect("Page2.aspx?value=" + mydata);

The above code will open Page2.aspx and now in order to get the value, you can write code on PageLoad event or any other method in code-behind file of Page2.aspx as follows

string mydata = Request.QueryString["value"];

No comments: