Friday, October 07, 2005

Context is great ... as long as you are working on the same server

Remember I posted a few days ago about my collegue thinking of using Context to pass data from one WebForm to another WebForm? Well, I tried and it worked pretty well. On the source I wrote:

private void buttonGo_Click(object sender, System.EventArgs e)
{
Context.Items["GameName"] = textGameName.Text;
Context.Items["GameDesc"] = textGameDesc.Text;
Server.Transfer("Dest.aspx");
}

And for the destination I wrote:

private void Page_Load(object sender, System.EventArgs e)
{
TextBox1.Text = Context.Items["GameName"].ToString();
TextBox2.Text = Context.Items["GameDesc"].ToString();
}

They all worked fine. However, notice that it only works for Server.Transfer. If you use Response.Redirect("Dest.aspx") , it won't work.

I am going to try out serialization and see if I can use the same scheme to transfer object from one page to another page.

0 Comments:

Post a Comment

<< Home