views:

37

answers:

2

I've a static page method in web form application and I want to call method on private class level variable from it as shown below. I'm using jQuery to call the page method.

private readonly ICatalogBLL _catalogBLL = new CatalogBLL();

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    _catalogBLL.GetSomething();
  }
}

[WebMethod]
public static UpdateSomething(int i)
{
   //Want to do as below. But can't call it from a static method.
   _catalogBLL.UpdateSomething();
}

UPDATE

If I call it as said by John Saunders, won't it use the same instance for requests from different users as it is within a static method?

+4  A: 

You can't. The page method is static. Your _catalogBLL is an instance member.

However, since you create a new instance of CatalogBLL on every request, why not do so once more?

[WebMethod]
public static UpdateSomething(int i)
{
   CatalogBLL catalogBLL = new CatalogBLL();
   catalogBLL.UpdateSomething();
}
John Saunders
+2  A: 

You can't call because pagemethods are static...

A static method is simply one that is disassociated from any instance of its containing class. The more common alternative is an instance method, which is a method whose result is dependent on the state of a particular instance of the class it belongs to.

Look at John saunder's answer..

Pandiya Chendur