• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 741
  • Last Modified:

After refresh I want to keep the old values

Hello :

I've this code to auto refresh my page. The problem is, everytime the page refresh I lost all session and variables values.
How I can keep the session values and variables values??
I need this really urgent. I really appreciate any help
Thanks

        HtmlMeta meta = new HtmlMeta();
        meta.HttpEquiv = "REFRESH";
        meta.Content = "15";
        Page.Header.Controls.Add(meta);
HtmlMeta meta = new HtmlMeta();
        meta.HttpEquiv = "REFRESH";
        meta.Content = "15";
        Page.Header.Controls.Add(meta);

Open in new window

0
nkoriginal
Asked:
nkoriginal
  • 3
  • 2
  • 2
1 Solution
 
RiteshShahCommented:
do you have viewstate enable? where do you assign session and variables?
0
 
oobaylyCommented:
I can't see an reason why you'd have any issues. By variables, do you mean GET or POST data?
How are you settings the session data?

The following code keeps the Session values & Querystring as expected (in IE6 & Firefox3)
<%@ Page Language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
  protected void Page_Load(object sender, EventArgs e) {
    if (Session["foo"] == null) {
      Session["foo"] = DateTime.Now;
    }
 
    HtmlMeta meta = new HtmlMeta();
    meta.HttpEquiv = "REFRESH";
    meta.Content = "5";
    Page.Header.Controls.Add(meta);
 
    QueryString.Text = Request.QueryString.ToString();
    FooSession.Text = Session["foo"].ToString();
 
  }
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
  Querystring: <asp:Label ID="QueryString" runat="server"></asp:Label><br />
  Session["foo"]: <asp:Label ID="FooSession" runat="server"></asp:Label>
</body>
</html>

Open in new window

0
 
nkoriginalAuthor Commented:
Yes I tried, but it doesn't work. Because  the refresh function is a clean up function too.
I tried to use java script function but it doesn't work because I've web services and user controls.

In this code:
        meta.HttpEquiv = "REFRESH";
        meta.Content = "15";
        Page.Header.Controls.Add(meta);

I need to retrieve some variables/values/session but I dont know to do it.

Thank you
 
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RiteshShahCommented:
you can assign values in Page_Init event and can see whether it makes any difference to you as it should work even without changing anything but you can try INIT event
0
 
nkoriginalAuthor Commented:
I don't know why is the problem with my session values.
When I call the page, I execute default.aspx, with a masterpage, inside the default.aspx I've a user control with a drop down list and I get the value from there.
Then I've the auto refresh page in that moment is when I lost the session/variables values.

Here's the code I using
    protected void Page_Load(object sender, EventArgs e)
    {
 
 
        if (Session["HourSelected"] == null)
        {
            Session["HourSelected"] = Convert.ToDouble(Search1.HourValue);
            Response.Write(Session["HourSelected"]);
        }
 
        HtmlMeta meta = new HtmlMeta();
        meta.HttpEquiv = "REFRESH";
        meta.Content = "5";
        Page.Header.Controls.Add(meta);
 
 
        Session["HourSelected"] = Convert.ToDouble(Search1.HourValue);
 
        timeIni = DateTime.Now.AddHours(Convert.ToDouble(Session["HourSelected"]));
        timeFin = DateTime.Now;
        GV_Servers.DataBind();
 
 
 
    }

Open in new window

0
 
oobaylyCommented:
Ok, when you use meta refresh, the browser will send a HTTP GET request, which the server interprets as a brand new request. If you were to check the Page.IsPostback property, you will see that its value is false.
This is why the control values have been lost. For the same reason, you won't be able to use the viewstate property either.
If you place a breakpoint where you test for the Session value being null, you should see that the session value is not null after a refresh. The problem is that you're filling it with default data from the Control.

For something like this, I'd recommend using the System.Web.UI.Timer class:
http://msdn.microsoft.com/en-us/library/system.web.ui.timer.aspx
0
 
nkoriginalAuthor Commented:
Thank you!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now