Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Loading UI Control From AJAX and C#

$
0
0

I am trying to dynamically load a PlaceHolder with a non-MVC *.ascx page from a AJAX call. But am running into an issue with the static aspect.

I cannot access the PlaceHolder as it's not a static member. My code is as follows:

[HTML]

<div id="DInfo"><asp:PlaceHolder ID="PlaceHolderDInfo" runat="server"></asp:PlaceHolder>  <div id="response"></div>  </div>

[C#]

    [WebMethod]
    public static void SetD()
    {
       //SOME LOGIC TO FIND CORRECT ASCX PAGE
       ...

       //Load the control 
       PlaceHolderDInfo.Controls.Add(LoadControl([path to ascx]));
    }

[AJAX]

$.ajax({
      type: "POST",
      url: "LivePlayer.aspx/SetD",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (response) {$("#response").html(response.d);
      },
      failure: function (response) {$("#response").html("error");
    }

The problem happens in the C# section as "PlaceHolderDInfo" throws the error:

  • "An object reference is required for the non-static field, method, or property..."

How can I reach the PlaceHolder from the SetD()method?

Thank you in advance


Viewing all articles
Browse latest Browse all 5678

Trending Articles