Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > XmlHttpPanel > Can the panel be used with a WebMethod in an aspx.cs?

Answered Can the panel be used with a WebMethod in an aspx.cs?

Feed from this thread
  • Posted on Sep 15, 2010 (permalink)

    Title says it all....the amount of asmx files I'm accumulating becasue I use (overuse? :) the RadXmlHttpPanel is getting a little crazy.

    Can I do a quick one or two in the page with a WebMethod? 

    Reply

  • Answer Pero Pero admin's avatar

    Posted on Sep 17, 2010 (permalink)

    Hello Steve,

    Indeed this is possible, and we will document this feature as soon as we can. It is done in the following way:

    1. Set EnablePageMethods="true" to the ScriptManager control on the page.
    2. Set RadXmlHttpPanel's WebMethodPath property to the path of the page containing the method in its code behind.
    3. Make sure the method is a static one (shared in VB).
    4. Make sure the method is marked as WebMethod

    For your convenience I have created a simple page demonstrating this. Here is the code:

    .aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PAGE_WebService.aspx.cs"
        Inherits="Default_Callback" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head id="Head1" runat="server">
        <title></title>
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function SetValue()
                {
                    var panel = $find("<%=XmlPanel1.ClientID %>");
                    panel.set_value("Some Value");
                }
            </script>
        </telerik:RadScriptBlock>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <div>
            <input value="Set Value" onclick="SetValue(); return false;" type="button" />
            <telerik:RadXmlHttpPanel ID="XmlPanel1" runat="server" EnableClientScriptEvaluation="true"
                WebMethodName="HelloWorld" WebMethodPath="~/PAGE_WebService.aspx">
            </telerik:RadXmlHttpPanel>
        </div>
        </form>
    </body>
    </html>


    .cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Script.Serialization;
    using System.Web.Services;
     
     
    public partial class Default_Callback : System.Web.UI.Page
    {
        [WebMethod]
        public static string HelloWorld()
        {
            return "Hello World called at:" + DateTime.Now.ToString();
        }
    }

    Regards,
    Pero
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Posted on Sep 17, 2010 (permalink)

    That's great news!

    Now let me throw you for another loops ;)

    Can it be done inside a Composite Control :D  What I'm doing in my Composites right now is exposing the path as a public property and in my page pointing that at an external ASMX whos class points back to the Assembly which contains the service.

    Reply

  • Answer Pero Pero admin's avatar

    Posted on Sep 22, 2010 (permalink)

    Hello Steve,

    I believe that this is not possible, because your custom composite control must inherit from System.Web.Services.WebService and System.Web.UI.WebControls.CompositeControl. This is not possible with C# and VB.NET, because they do not support multiple inheritance, which means that you cannot inherit from multiple base classes. WebService and CompositeControl are both base classes, and you can derive only one of them.

    Greetings,
    Pero
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > XmlHttpPanel > Can the panel be used with a WebMethod in an aspx.cs?