views:

41

answers:

1

I'm using pagemethods to call a method from javascript, is there a way to access the page's controls from the method in codebehind (marked as static)? The problem is that the pagemethod nedds to load a business entity and load it to the page, and the structure is complex.

Thanks in advance for any help.

+1  A: 

Even in a static/shared method you can access your page.

C#:

(WebForm1)HttpContext.Current.Handler

VB.Net:

DirectCast(HttpContext.Current.Handler, WebForm1)

Where WebForm1 is your page-type. Then you can access all your controls.

Tim Schmelter
Thanks for the info, but when I access the Controls property of the page there are none.
Argons
Sorry, i forgot that in a WebMethod no Viewstate is loaded, its not part of the page-lifecycle for performance reasons. So i have no suggestions but to pass values from javascript to this method.
Tim Schmelter
Is it an option to store relevant controls or objects in the session? You can access session from static context with:HttpContext.Current.Session
Tim Schmelter