Genpact Cora Knowledge Center

Support

Isolate First Load from Post Backs

At first glance, the Page.IsPostback property does not serve any function in Cora SeQuence, since its value is always true. To bypass this, you can push values to the view state. The view state refreshes when you press the F5 button, or when you reload the site. As long as you initialize the view state, the value is retained in subsequent postbacks, giving you a way to isolate the first load of the page from a standard postback. 

This is especially useful if you have to calculate values on the pre-render that you don't want recalculated for every postback action on your form control.

In the form control

private bool PerformRefresh
        {
            get
            {
                object performRefresh = this.ViewState["PerformRefresh"];
                return performRefresh != null && (bool)performRefresh;
            }
            set
            {
                this.ViewState["PerformRefresh"] = value;
            }
        }

In the page event handler

 protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (!PerformRefresh)
            {
                CacheRefresh();   //The method or code you need to run.
                PerformRefresh = true;
            }
        }