Search code examples
c#asp.net.netcode-behindwebmethod

How to get Page.UICulture in a static WebMethod?


How to get the Page.UICulture in a static WebMethod function. The following gives me an error:

Page.UICulture = System.Threading.Thread.CurrentThread.CurrentCulture;

The error I get:

An object reference is required for the non static field,method or property


Solution

  • Simply, you can't.

    The property Page is not available to a static method, and that makes sense, since in the context of that static WebMethod, you don't have a page.

    You could save the relevant properties in a Session variable and get it from the session info in your WebMethod. Note you have to set [WebMethod(EnableSession=true)] to be able to get the session info from a WebMethod.