Monday, November 22, 2010

Page flicker on postback

I was working on a form where one dropdownlist is populated based on values of selected item in another dropdown and it caused the page to flicker each time.

So, Robicool from work gave me this cool piece of code to stop the annoyng page flickers


 protected void Page_PreInit(object sender, EventArgs e)
    {

        if (Request.Browser.IsBrowser("IE"))
        {
            string v = Request.Browser.Version;
            if (v.Length > 0)
                v = v.Substring(0, 1);
            if ((v == "7") || (v == "6"))
            {
                SmartNavigation = true;
                MaintainScrollPositionOnPostBack = false;
            }
            else
            {
                SmartNavigation = false;
                MaintainScrollPositionOnPostBack = true;
            }
        }
        else
        {
            SmartNavigation = false;
            MaintainScrollPositionOnPostBack = true;
        }
    }

No comments: