Different Methods to Pass Values between Web Forms
Pass Value from one page to another page is an important concept.The important part of website development is how to manage data across web page.There are many different ways to perform that Task.some of methods are cookies,query string,session and server.transfer.
Pass Value from one page to another page is an important concept.The important part of website development is how to manage data across web page.There are many different ways to perform that Task.some of them are following.
Cookies:
A small piece of information sent by the web server to User's web browser during a request, which is stored on user's system in the form of a text file(mostly as notepad file).
How to use a cookie.
HttpCookie samplecookie = new HttpCookie("mycookie");
samplecookie.Value = TextBox1.Text;
samplecookie.Expires = DateTime.Now.AddHours(1);
Response.Cookies.Add(samplecookie);
Response.Redirect("default2.aspx");
On second Page how Retrieve value using cookies.
Label1.Text = Request.Cookies["mycookie"].Value;
Query String:
This is another way to pass value between pages.
in it we have to use a question mark (?) as separator. "&" is use to pass multiple query strings.
how to use query string
Response.Redirect("default2.aspx?pass="+TextBox2.Text);
Retrieve value using Query string
Label2.Text = Request.QueryString["pass"]
Sessions:
it is server side state management method.this is most secure and most acceptable way of cross page posting
how to use session on page
Session["user"] = txtName.Text;
on second page
string str=Session["user"].ToString();
Server.Transfer:
it can be used by enabling second parameter to true.
how to use Server.Transfer on page
Server.Transfer("Default.aspx", true);
on second page
Label1.Text = Request.Form["DropdownList1"];
how to insert image in ado.net using c#