Both funtions are giving the same result, which is the site visitor will be redirected to another webpage, but there are small differences betweeb both that will make you choose one of them based on your suitation.
Response.Redirect function redirects the user to another page, the changed easly noticed by the url changing, it'll tell you exactly where you are, and you can bookmark the page you're in.
Server.Transfare is a moving process inside the same domain, site visitor will not feel the transfaring process, the URL will not be changed, Server.Transfare dosn't disply the true URL, so the user could be misslead if he try to Bookmark or email the page to a friend.
If you try to use Server.Transfare to redirect to a page outside your domain, you'll got the followign error msg
Invalid path for child request 'http://www.anotherdomain.com'. A virtual path is expected.
The example below showing how can you use Context.Handler to transfare data between pages in Server.Transfare function.
Assume that you have two pages: FirstPage.aspx and SecondPage.aspx
In FirstPage.aspx.cs write the following code:
void Page_Load(object sender, EventArgs e)
{
Server.Transfer("secondpage.aspx");
}
internal Hashtable Value
{
get
{
Hashtable obj = new Hashtable();
obj["Name"] = "My Name";
obj["Second"] = "My Second Name";
obj["Address"] = "Shoubra";
return obj;
}
}
In the ScondPage.aspx.cs write the following code
protected void Page_Load(object sender, EventArgs e)
{
Hashtable obj = new Hashtable();
if
(!IsPostBack)
{
FirstPage ParentPage;
ParentPage = (FirestPage)Context.Handler;
obj = ParentPage.Value;
Response.Write("<br><br>");
foreach (DictionaryEntry di in obj)
{
Response.Write(di.Key + " : " + di.Value);
Response.Write("<br>");
}
}