Wednesday, September 06, 2006

ASP.net and the iframe tag

When building the sudoku site that lets others get a sudoku grid on their site...I noticed a big problem with asp pages and iframes:Session variables and cookies are lost during post back.
So trying this:
Session["MyVar"] = "somevalue";
and then after a post-back checking the session variable like this:
if (Session["MyVar"] == null)
Response.Write("NULL");
you will get NULL written on your site.
The way I solved this problem is this: I added a invisible textbox that holds the value of the session variable,like this:
MyTextBox.Visible=False;
MyTextBox.Text = "somevalue";
and then when checking the value you simply get the value stored in the textbox.
The solution is really old-fashioned and not pretty at all...but at least made the site work for the time being...until I find a good solution.

No comments: