1

I am making an application in which we may have 5 or 6 steps. In first step, i will select the report which i need and save&continue..it will get me to second step...like so... my problem is according to functionality, when i hit on the browser back button i need to go to previous page. and again when i press it second time it has to go to my home page, but it is redirecting me to the previous page. It is working in all browsers except in chrome and safari. I am inserting my code for reference..please help me to solve this..

protected void Page_Load(object sender, EventArgs e)
{

    DisableHistory();
    lnkBackBrowse.Style["visibility"] = "hidden";
    if (Session["UserId"] != null)
    {
        if (Convert.ToInt32(Session["UserId"].ToString()) == 0)
        {
            TopNavigationMenu.Style["visibility"] = "hidden";
            NavigationMenu.Style["visibility"] = "hidden";

            if (!Request.Url.ToString().Contains("Home") && !Request.Url.ToString().Contains("SaveandLogout"))
                Response.Redirect("Home.aspx");
        }
        else
        {
            TopNavigationMenu.Items[0].Text = "Welcome :" + Session["UserName"].ToString();
            TopNavigationMenu.Style["visibility"] = "visible";
            NavigationMenu.Style["visibility"] = "visible";

            if (Session["FirstTimeLogged"] != null && Convert.ToBoolean(Session["FirstTimeLogged"]) == true)
            {
                TopNavigationMenu.Enabled = false;
                NavigationMenu.Enabled = false;

                if (!Request.Url.ToString().Contains("MyAccount"))
                    Response.Redirect("Home.aspx");
            }
            else
            {
                GenerateLinks(Session["RoleId"].ToString());
                TopNavigationMenu.Enabled = true;
                NavigationMenu.Enabled = true;
                //TopNavigationMenu.Items[1].Text = "Support <img src='Images/bullet_arrow_down.png' alt='down' title='' />";

                if (Request.Url.ToString().Contains("Home"))
                    Response.Redirect("Default.aspx");

                if (!IsPostBack)
                {
                    string strPrevPg = "", strCurrPg = "";
                    if (Request.UrlReferrer != null)
                    {
                        strPrevPg = Request.UrlReferrer.AbsolutePath.ToString();
                        strPrevPg = strPrevPg.Substring(strPrevPg.IndexOf("/", 1) + 1, strPrevPg.Length - (strPrevPg.IndexOf("/", 1) + 1));
                        strPrevPg += Request.UrlReferrer.Query.ToString();
                    }
                    strCurrPg = Request.Url.AbsolutePath.ToString();
                    strCurrPg = strCurrPg.Substring(strCurrPg.IndexOf("/", 1) + 1, strCurrPg.Length - (strCurrPg.IndexOf("/", 1) + 1));

                    bool bFlag;
                    bFlag = Convert.ToBoolean(Session["goBackPg"]);

                    if (Session["PrevPg"] != null)
                    {
                        if (strCurrPg == Session["PrevPg"].ToString())
                        {
                            if (bFlag)
                            {
                                Session["CurrPg"] = strCurrPg;
                                Session["PrevPg"] = "Default.aspx";
                                bFlag = false;
                                Session["goBackPg"] = bFlag;
                            }
                            else
                            {
                                Session["CurrPg"] = strCurrPg;
                                Session["PrevPg"] = strPrevPg;
                            }
                        }
                        else
                        {
                            Session["CurrPg"] = strCurrPg;
                            Session["PrevPg"] = strPrevPg;
                            bFlag = false;
                            Session["goBackPg"] = bFlag;
                        }
                    }

                }
            }
        }
    }
    else
    {
        Response.Redirect("home.aspx");
    }
}

1 Answer 1

0

Those browsers are showing you cached content when you press the back button.

You can debug and check, your server is not being hit. This Session code will not work.

You could tell the browser not to cache the page. That way if the user wanted to go back, he would have to reload the content.

6
  • But it is working fine in the remaining browsers without issues.I have used backfix.js file which has support for opera, safari and ie but not added support for chrome
    – Mythili
    Aug 14, 2012 at 10:37
  • Of-course it will work fine in other browsers. It is a browser specific optimization. Aug 14, 2012 at 10:39
  • Can you ellobarate a little bit more.Browser needs to cache the previous information .and also the above functionality should work
    – Mythili
    Aug 23, 2012 at 6:55
  • protected void lnkBackBrowse_Click(object sender, EventArgs e) { bool bFlag = true; Session["goBackPg"] = bFlag; Response.Redirect(Session["PrevPg"].ToString()); Response.Redirect("Default.aspx"); }This code is not recogniging in chrome and safari for detecting in backbutton
    – Mythili
    Sep 17, 2012 at 13:27
  • What do you expect that code to do? Only the first of those Response.Redirect will fire. Sep 17, 2012 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.