How to pass the values from aspx page to asp page in a same projectHow to pass the values from aspx page to asp page in a same project.
If you have asp and asp.net pages in your project and you want to send the values from asp.net page to asp page then there are two ways;
1) Using Database
2) Using Cookies
Sometimes using database is not useful for us then we can use cookies for that task. You can use session for that because sessions can’t carry the values from one asp.net page to asp page.
Now see how we can use cookies.
A cookie is stored on the client's machine by their web browser software. To set a cookie, we include information in an HttpResponse that instructs the browser to save a cookie on the client's system. Here's the basic code for writing a Cookie in ASP.NET.
Using System.Web;
Response.Cookies["tutorials”].Value = "DotNetLogix”;
And to read the cookie back:
Response.Write(Request.Cookies["tutorials"].Value);
Note that for security reasons you can only read a cookie that was set within the same domain name.
Sometimes you may need a collection of stored items, such as user address details. In this case you could read in a cookie collection like this:
HttpCookieCollection cookies = Request.Cookies;
for(int n=0;n<=cookies.Count-1;n++)
{
HttpCookie cookie = cookies[n];
Response.Write("
Name: " + cookie.Name + "
");
Response.Write("Expiry: " + cookie.Expires + "
");
Response.Write("Address1: " + cookie.Address1+ "
");
Response.Write("Address2: " + cookie.Address2+ "
");
Response.Write("City: " + cookie.City+ "
");
Response.Write("Zip: " + cookie.Zip+ "
");
}
Finally, you can see details of cookies during development, by turning on tracing in ASP.NET. Within the @Page directive at the start of the page simply adds Trace="true”:
<%@ Page trace="true" language="c#" Codebehind="page.aspx.cs" Inherits="MyPage" %>