user2895432
user2895432

Reputation:

Calling a Function in MasterPage code behind from App_Code .cs file?

I have a file in the App_Code file which is some legacy code, that I use to control Login and sessions. Ideally, once I am logged in, I wish to update the ..Master.cs to fire a function to update the layout (some panels, become enabled etc).

I can access App_Code easily from Code Behind, though I'm unable to figure out how to do this the other way round.

MasterPage.master.cs (code behind)

 public static class MasterPage : System.Web.UI.MasterPage{
      ...
      public static void LogInCB{
        //stufff
      }
      ...
  }

App_Code (something.cs)

 public static string(){

     //Master.LogInCB();     -tried
     //System.Web.UI.MasterPage.LogInCB();      -tried
     return something;
}

I'm happy to accept links to official MS documents on things about this.

Upvotes: 1

Views: 1462

Answers (1)

MikeSmithDev
MikeSmithDev

Reputation: 15797

The code-behind doesn't know what master page you are using. One way to fix this is to cast the Page.Master as your master page class. Once you do that, it will intellisense available functions:

YourNameSpace.MasterPage m = (YourNameSpace.MasterPage)Page.Master;
m.LogInCB();

Upvotes: 1

Related Questions