server.transfer vs response.redirect
-
Please tell me the exact difference between server.transfer and response.redirect.
-
Please tell me the exact difference between server.transfer and response.redirect.
http://www.google.co.in/search?hl=en&q=server.transfer+response.redirect+&btnG=Google+Search&meta= Best Regards, Apurva Kaushal
-
Please tell me the exact difference between server.transfer and response.redirect.
-
Please tell me the exact difference between server.transfer and response.redirect.
Using Querystring Querystring is a day old mechanism to pass values across pages. The main advantage of this method is it is very simple. However, disadvantages are the values are visible in the browser address bar and you can not pass objects this way. This method is best suited when you want to pass small number of values that need not be secured from others. In order to implement this method you will follow these steps: § Create the web form with controls § Provide some button or link button that posts the form back § In the click event of the button create a string that holds URL for another § Add control values to this URL as querystring parameters § Response.Redirect to another form with this URL Following code snippet shows how it works: Source Web Form private void Button1_Click (object sender, System.EventArgs e) { string url; url="anotherwebform.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text; Response.Redirect(url); } Destination Web Form private void Page_Load (object sender, System.EventArgs e) { Label1.Text=Request.QueryString["name"]; Label2.Text=Request.QueryString["email"]; } Server.Transfer This is yet another way to pass values across pages. Here you store control values in session variables and access them in another web form. However, as you know storing too much data in session can be an overhead on the server. So, you should use this method with care. Also, it requires some kind of clean up action from your side so that unwanted session variables are removed. The typical sequence of steps will be as follows: § Create the web form with controls § Provide some button or link button that posts the form back § In the click event of the button add session variables and set them to control values § Response.Redirect to another form § In that form access Session variables and remove them if necessary Following code shows this in action: Source Web Form private void Button1_Click (object sender, System.EventArgs e) { //textbox1 and textbox2 are webform //controls Session["name"]=TextBox1.Text; Session["email"]=TextBox2.Text; Server.Transfer("anotherwebform.aspx"); } Destination Web Form private void Page_Load (object sender, System.EventArgs e) { Label1.Text=Session["name"].ToString(); Label2.Text=Session["email"].ToString(); Session.Remove("name"); Session.Remove("email"); }