tags:

views:

21

answers:

1

I don't really have a real world problem, yet, but I'm trying to learn more about Context.Session[] variables and the postback mechanism by writing a basic little image deally. To do this I have an asp:image control with the ImageUrl set to "image.aspx" on my test.aspx page.

image.aspx simply reads the Context.Session["test"] variable and calls the gfx.DrawString(Context.Session["test"],...) to a canvas. This part is easy.

Then on test.aspx I also have an asp:button. When the button is pressed, the OnClick method changes the Context.Session["test"] to the current time using DateTime.Now.

Now here is what I'm trying to do. I want the button to perform a postback so that it can update Context.Session["test"] variable but I don't want the page to reload, then in javascript I want to refresh the src field on the image after a small time delay to allow the session variable to change.

I'm essentially trying to update the session variable and the image on the button click without the page appearing to reload.

Is it even possible to update session variables without a page refresh?

Is this possible, or am I completely off base?

+1  A: 

To update session variables, you have to get to the server - which is where they are.

To get to the server without page appearing to reload, use AJAX.

There are various ways to use AJAX the most basic using the XMLHTTPRequest and XMLHTTPResponse classes.

InSane
I've realized the errors of my ways. My entire idea requires AJAX, or some other work around. I'm going to use querystrings in the image.aspx to set new session variables on image.aspx load. I of course have no idea how to chagne query strings in JS though. Off to learn more.
Shawn