Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 23, 2010 @ 16:04
    Jeroen Breuer
    0

    Call webservice from javascript within tree

    Hello,

    I'm trying to create my own delete action for a custom tree. I already created the tree and the action, but now I'd like to call a webservice which can perform the delete code (just like umbraco does when deleting a node). I've already got the webservice, but I can't call it yet. I've found the following lines of code at several places inside the Umbraco source:

    ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/codeEditorSave.asmx"));
    ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/legacyAjaxCalls.asmx"));

    Now I need to add my ServiceReference to the ScriptManager, but I don't have a place to call this code.

    In 'public class LoadLocationTree : BaseTree' I can't call this code, because I don't have the Page object. Is there some way to solve this and has anyone got experience with this?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 24, 2010 @ 08:24
    Jeroen Breuer
    0

    I've found a solution, but it's not really what I wanted. Currently I adjusted the umbraco.aspx page and changed the following:

        <asp:ScriptManager runat="server" ID="umbracoScriptManager">
            <Services>
                <asp:ServiceReference Path="webservices/legacyAjaxCalls.asmx" />
    
                <%--Extra ServiceReference for adding a custom WebService.--%>
                <asp:ServiceReference Path="/usercontrols/Sections/TreeWebService.asmx" />
            </Services>
        </asp:ScriptManager>

    This works, but it requires a small change in a page I´d rather not change. Does anybody have a better solution?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 13, 2010 @ 11:03
    Jeroen Breuer
    100

    I now have a better solution for this using jQuery. Here is part of my delete action:

    public string Alias
    {
        get
        {
            return "delete";
        }
    }
    
    public string JsFunctionName
    {
        get
        {
            return "DeleteCategory()";
        }
    }
    
    public string JsSource
    {
        get
        {
            //Assign a function.
            return @"function DeleteCategory()
                {
                    if(confirm('Are you sure you want to delete this category and its children?'))
                    {
                        $.ajax({
                            type: ""POST"",
                            url: """ + IOHelper.ResolveUrl(SystemDirectories.Umbraco) + @"/customSections/products/ProductWebService.asmx/DeleteCategory"",
                            data: '{ ""categoryId"": ' + UmbClientMgr.mainTree().getActionNode().nodeId + '}',
                            contentType: ""application/json; charset=utf-8"",
                            dataType: ""json"",
                            success: function (msg) {
                                if(msg.d)
                                {
                                    jQuery(window.top).trigger('nodeDeleted', []);
                                }
                            }
                        });
    
                    }
                }";
        }
    }

    I still call the custom webservice, but instead of calling UnidekCorporate.WebApplication.Sections.Products.ProductWebService.DeleteCategory(id) I go to the webservice path with an jQuery ajax call. This way I don't need to update the /umbraco/umbraco.aspx page. This sample works in Umbraco 4.5.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft