Link to home
Start Free TrialLog in
Avatar of nkoriginal
nkoriginalFlag for Spain

asked on

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

Avatar of RiteshShah
RiteshShah
Flag of India image

do you have viewstate enable? where do you assign session and variables?
Avatar of oobayly
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

Avatar of nkoriginal

ASKER

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
 
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
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

ASKER CERTIFIED SOLUTION
Avatar of oobayly
oobayly
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!