How to call a method only once in the first page load in the master page

Anyname Donotcare picture Anyname Donotcare · Apr 3, 2013 · Viewed 9.3k times · Source

I have the following case:

Page1.aspx this page has the master page master.aspx.

I have some code in the master page :

 if (!Page.IsPostBack)
            {
                adjustServiceBar();

            }

when i click any button in the Page1.aspxit enters the !Page.IsPostBack and execute the method !!

i want this method in the !Page.IsPostBack) only

Answer

mtsiakiris picture mtsiakiris · Apr 3, 2013

One way to do this is to set a session variable and then check that variable to ensure your code will fire only once. Another way is to set a hidden control on your form and play with its text or value property.

According to each scenario the solution may be very complex such as custom derived masterpages and pages that extend the current events functionality to suit your needs.