Shawn
Shawn

Reputation: 869

Sesssion Variables and preventing asp:button from reloading page

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?

Upvotes: 0

Views: 545

Answers (1)

Jagmag
Jagmag

Reputation: 10356

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.

Upvotes: 1

Related Questions