locked
Accessing master page method public void from WebMethod in c# RRS feed

  • Question

  • User-2004582644 posted

    Hi,

    I have insert this a public void called SetUser() on master page

        public void SetUser()
        {
           Page.User.Identity.Name.ToLower();
        }

    I need call the SetUser() from content page Method (static WebMethod)

    I've tried in this mode, but on VS 2019 debug the error

    "an object reference is required for the non-static field, method or property..."

    Please can you help me?

    my code below

    [WebMethod(EnableSession = true)]
    [ScriptMethod]
    public static void Savepnauttlc(pnauttlcweb teleco)
    {
        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();
    
        ((Mp)Master).SetUser();
    }
    Saturday, May 30, 2020 6:49 AM

Answers

  • User475983607 posted

    It is not possible to call a master page method from a static web method.  This is a fundamental concept to understand in C#.  Basically the master page does not exist during the web request.  Only the web method is called.

    Use JavaScript/jQuery to update the current page HTML.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 30, 2020 10:47 AM

All replies

  • User475983607 posted

    It is not possible to call a master page method from a static web method.  This is a fundamental concept to understand in C#.  Basically the master page does not exist during the web request.  Only the web method is called.

    Use JavaScript/jQuery to update the current page HTML.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 30, 2020 10:47 AM
  • User-2004582644 posted

    Thank you for reply

    Have a great we

    Saturday, May 30, 2020 11:03 AM