Search code examples
pagemethods

PageMethod and page control access?


Pagemethods are static and that is why we can not access page control from pagemethod, but I heard we can access user control from the pagemethod. Is it true?

If yes, then how can user control be accessed from static method? I search Google to know the reason in detail but found none, so if any body knows the reason then please discuss in detail.


Solution

  • You cannot access user control objects that are part of the page. What you can do is create new User control objects and call their method etc ex: var myuc = new MyUserControl() and probably then you can call render method to get the HTML of the user control and send it as response "string" from page method, but this is not a proper way of using user control and should be avoided.