views:

101

answers:

2

is there a way to reference the page control in a webservice? something like this:

[WebService(Namespace = "http://test.org/")]
public class Search : System.Web.Services.WebService
    {

      public Search()
     {
             Page.Controls.Add(new Control()); // can I get a reference to Page?

      }
   }
A: 

This seems like a very odd design approach. In general a called method should have no knowledge about, or dependencies on the caller. In this case the web method would need knowledge about the page calling it. I don't think this is possible, and even if it was, consider the possibility that it may not even be a page calling the web service. It could be any kind of application.

Fredrik Mörk
i was just asking but you make perfect sense
Ayyash
A: 

What you are trying to do (at least the way you are trying to do it) is impossible. The web service cannot, at server side, modify the page by modifying the control tree, server side. The page object that was rendered to the user does not exists any more.

I think that what you should be doing instead is using an update panel. That will allow you to do exactly what you want to.

Pete