Copied to clipboard

Flag this post as spam?

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


  • Fredrik 89 posts 108 karma points
    Oct 29, 2010 @ 10:48
    Fredrik
    0

    Can't get this to work properly, what's the problem? (Usercontrol, Ajax, Webservice)

    I'm trying to create a Autocomplete search in Ajax using ajax toolkit 4.

    I get no errors with the following code but the control does not work at all.

    Ascx and asmx are placed in the usercontrol folder and the dll in the bin folder.

     

    As I see it there could be two possible problems:

    • Ajax toolkit 4 does not work with umbraco 4.5
    • The webservice method is not found

     

    ascx.cs file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    namespace ParvusProductSearch
    {
        public partial class ProductSearch : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
          
            protected void Button1_Click(object sender, EventArgs e)
            {
                string text = TextBox1.Text;
                Response.Redirect("search.aspx?searchterm=" + text);
            }

        }
    }

    ascx markup

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProductSearch.ascx.cs" Inherits="ParvusProductSearch.ProductSearch"%>
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
        TargetControlID="TextBox1" UseContextKey="True" CompletionInterval="10" CompletionSetCount="10" ServicePath="~/WebService1.asmx" ServiceMethod="GetNames"></asp:AutoCompleteExtender>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

     

    Webservice

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using umbraco.presentation.nodeFactory;
    namespace ParvusProductSearch
    {
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
        // [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public string[] GetNames(string prefixText)
            {
                List<String> namn = new List<String>();
                Node node = new umbraco.presentation.nodeFactory.Node(1079);
                foreach (Node child in node.Children)
                {
                    foreach (Node child2 in child.Children)
                    {

                        foreach (Node child3 in child2.Children)
                        {
                            if (child3.NodeTypeAlias == "Product" && child3.Name.Contains(prefixText) || child3.NodeTypeAlias == "Product" && child3.GetProperty("articleNr").Value.Contains(prefixText))
                            {
                                namn.Add(child3.Name);
                            }
                            foreach (Node child4 in child3.Children)
                            {
                                if (child4.NodeTypeAlias == "Product" && child4.Name.Contains(prefixText) || child4.NodeTypeAlias == "Product" && child4.GetProperty("articleNr").Value.Contains(prefixText))
                                {
                                    namn.Add(child4.Name);
                                }
                            }
                        }
                    }
                }
                return namn.ToArray();
            }
        }
    }

     

  • Fredrik 89 posts 108 karma points
    Nov 03, 2010 @ 09:16
    Fredrik
    0

    I have not got this working yet. Im thinking that the webservice is not found(placed in the usercontrol folder along with the ascx file with this ServicePath="~/WebService1.asmx" in the ascx

    Other things ive tried with without further success:

    1. Uncommented this line: // [System.Web.Script.Services.ScriptService].  It's needed.

    2. Used this signature: public string[] GetNames(string prefixText, int count)

    3. Removed this: UseContextKey="True"

     

  • Rory 59 posts 84 karma points
    Jul 02, 2011 @ 18:34
    Rory
    0

    I'm having a similar problem. Did you ever get it to work? I've also tried moving the webservice file to the /build folder as it is referenced in my usercontrol as ServicePath="~/Webservice.asmx". This does not fire the webservice either.

    cheers

    Rory

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 02, 2011 @ 21:21
    Tom Fulton
    0

    Don't have much experience with this, but are you able to access the webservice directly in your browser?  You might need to exclude it from Umbraco's handlers in the web.config (key umbracoReservedUrls I believe) or place it in the umbraco folder as this is excluded already.  Also, wouldn't /WebService.asmx look on the root of the site, so in that case shouldn't the webservice be placed in the root (/)?

  • Rory 59 posts 84 karma points
    Jul 02, 2011 @ 23:10
    Rory
    0

    Tom, thank you. Accessing it directly enabled me to spot a bug, which once fixed meant I could properly access it in the browser...and also then worked properly from the UserControl on the Umbraco page. The /build folder is indeed my site root, so yes the webservice is in the root (not sure if this is a good idea or not), but it all works fine now without modifying umbracoReservedUrls.

    Thanks

    Rory

Please Sign in or register to post replies

Write your reply to:

Draft