0

I`m trying to access asp.net controls like label, PlaceHolder etc in my web service class. I have tried a few ways to do it but no luck.

This is my control in ASPX page

<asp:PlaceHolder ID="ph1" runat="server"></asp:PlaceHolder>

My WebService class inherits my ASPX class

[WebMethod]
    public string buildFunctionParams(int one, string two)
    {
        TextBox txt = new TextBox();
        txt.ID = "test";

        ph1.Controls.Add(txt);
        return "Build success";
    }

This gives an error object ref is not set to an instance of object. I understand I cannot access my asp controls outside the aspx class. Is there a way I can pass my controls to webservice?

6
  • Aren't the Webmethods supposed to be static ?
    – fahadash
    Jul 1, 2014 at 5:59
  • You can't do that, you are trying to combine Web over HTTP and SOAP over HTTP... Whats the point in doing that?
    – fahadash
    Jul 1, 2014 at 6:01
  • the ph1 is a placeholder. I want to add controls on JQuery call to my webmethod Jul 1, 2014 at 6:11
  • I understand I have changed my function in another way. Cheers Jul 1, 2014 at 6:14
  • You would rather make a postback call for that.
    – fahadash
    Jul 1, 2014 at 6:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.