Web Serivce return null

16 posts, 1 answers
  1. Jason Lee
    Jason Lee avatar
    185 posts
    Member since:
    Oct 2004

    Posted 13 Jan 2008 Link to this post

    Dear Sir,

    I am using load-on-demand ( web service )...
    is it possible to return null object in server-side and client-side doesn't throw a javascript error?


  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 14 Jan 2008 Link to this post

    Hello Jason Lee,

    What about returning an empty array. Is that acceptable for you?
        public RadComboBoxItemData[] GetProducts(object context)
        {
            IDictionary<string, object> contextDictionary = (IDictionary<string, object>) context;

            SqlConnection connection =
                        new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString);

            string filterString = ((string) contextDictionary["FilterString"]).ToLower();
            SqlCommand selectCommand =
                new SqlCommand(@"    SELECT ID, ProductName FROM Products
                                    WHERE LOWER(ProductName) LIKE '" + filterString + "%'", connection);

            SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
            DataTable products = new DataTable();
            adapter.Fill(products);

            List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(products.Rows.Count);
            foreach (DataRow row in products.Rows)
            {
                RadComboBoxItemData itemData = new RadComboBoxItemData();
                itemData.Text = row["ProductName"].ToString();
                itemData.Value = row["ID"].ToString();
                result.Add(itemData);
            }

            return result.ToArray();
        }

    You can leave the "result" list empty.

    Regards,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Jason Lee
    Jason Lee avatar
    185 posts
    Member since:
    Oct 2004

    Posted 15 Jan 2008 Link to this post

    Dear Nick,

    Sure....I will use empty node....
    Thank you
  4. Josemilo
    Josemilo avatar
    3 posts
    Member since:
    Jan 2008

    Posted 23 Jan 2008 Link to this post

    Hi Nick,

    I was looking for some examples regarding Load on Demand using Web Service for RadTreeview.  Can you give me a similar web service method example?  How will this populate the nodes in the Treeview?

    If possible, can you explain this Load on demand mechanism step by step.  I want to know how different is this approach with the others.

    Thanks,
    Jojit
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 23 Jan 2008 Link to this post

    Hi Josemilo,

    Please check out our online demo - Load-On-Demand through a Web Service - for a reference on how it should be implemented.

    Greetings,
    Simeon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Josemilo
    Josemilo avatar
    3 posts
    Member since:
    Jan 2008

    Posted 24 Jan 2008 Link to this post

    Hi Simeon,

    I wasn't able to make my stuff work.  Can you take a look at what I am  missing here...

    Im getting the message..."The server method Get_RadTreeNodeData failed"

    Default.aspx
    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">   
            function nodePopulating(sender, eventArgs)
            {
                var node = eventArgs.get_node();
                var context = eventArgs.get_context();
                context["ID"] = node.get_value();                       
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        </div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
            </telerik:RadStyleSheetManager>
            &nbsp;
            <telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="True" LoadingStatusPosition="BeforeNodeText"
                Skin="Vista" OnClientNodePopulating="nodePopulating">
                <WebServiceSettings Path="http://localhost/DataService/Service.asmx" Method="Get_RadTreeNodeData" />
                <Nodes>
                    <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Handsets" Value="1">
                        <Nodes>
                            <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Alcatel" Value="2">
                            </telerik:RadTreeNode>
                            <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Blackberry" Value="10">
                            </telerik:RadTreeNode>
                            <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Dopod" Value="18">
                            </telerik:RadTreeNode>
                            <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Ericsson" Value="20">
                            </telerik:RadTreeNode>
                            <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Nokia" Value="40">
                            </telerik:RadTreeNode>
                        </Nodes>
                    </telerik:RadTreeNode>
                </Nodes>
                <CollapseAnimation Duration="100" Type="OutQuint" />
                <ExpandAnimation Duration="100" Type="OutQuart" />
            </telerik:RadTreeView>       
        </form>
    </body>
    </html>

    Web Service


    <WebMethod()> _
        Public Function Get_RadTreeNodeData(ByVal node As RadTreeNodeData, ByVal context As Object) As RadTreeNodeData()
            Dim _serviceOperations As New ServiceOperations
            Dim rtNodeData() As RadTreeNodeData
            rtNodeData = _serviceOperations.Get_RadTreeNodeData(context)
            Return rtNodeData
        End Function

    Public Function Get_RadTreeNodeData(ByVal context As Object) As RadTreeNodeData()
            Dim contextDictionary As New Dictionary(Of String, Object)
            contextDictionary = Convert.ChangeType(context, contextDictionary.GetType)

            Dim connection As SqlConnection = New SqlConnection(_conString)
            'Dim filterString As String = Convert.ToString(contextDictionary("FilterString")).ToLower

            'Dim selectCommand As SqlCommand = New SqlCommand(" SELECT ID, Text FROM Handsets_Tree WHERE LOWER(Text) LIKE '" + filterString + "%'", connection)
            Dim selectCommand As SqlCommand = New SqlCommand(" SELECT ID, Text FROM Handsets_Tree WHERE Parent_id Is Null ", connection)
            Dim adapter As SqlDataAdapter = New SqlDataAdapter(selectCommand)
            Dim products As New DataTable
            adapter.Fill(products)

            Dim result As List(Of RadTreeNodeData) = New List(Of RadTreeNodeData)(products.Rows.Count)
            For Each row As DataRow In products.Rows
                Dim itemData As New RadTreeNodeData
                itemData.Text = Convert.ToString(row("Text"))
                itemData.Value = Convert.ToString(row("ID"))
                result.Add(itemData)
            Next
            Return result.ToArray
        End Function

  7. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 25 Jan 2008 Link to this post

    Hello Josemilo,

    Could you please check whether the path of the Web Service in your .aspx code matches the real location of the Web Service?

    Your code seems to be OK.

    All the best,
    Simeon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. jim
    jim avatar
    7 posts
    Member since:
    Nov 2007

    Posted 29 Jan 2008 Link to this post

    when i use the webservice which located in the same project like:<WebServiceSettings Path="testwebservice.asmx" Method="GetTreeViewCategories" />. the load on demand(webservice) works fine.
    but i try to use an actural webservice like :<WebServiceSettings Path="http://localhost/WebSite1/testwebservice.asmx" Method="GetTreeViewCategories" /> . it doesnot work.

    is there any different setting for that?
  9. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 30 Jan 2008 Link to this post

    Hi jim,

    To make sure that the WebService is visible from its location you can try to open it directly like this: http://localhost/WebSite1/testwebservice.asmx. If this works, then the project should work, too. Otherwise, the WebService is not found, hence the error.

    Could you please check this first and let us know of the results.

    Kind regards,
    Simeon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. jim
    jim avatar
    7 posts
    Member since:
    Nov 2007

    Posted 30 Jan 2008 Link to this post

    yes, the webservice is visible from http://localhost/WebSite1/testwebservice.asmx and all the webmethod works fine from that location.
  11. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 01 Feb 2008 Link to this post

    Hi jim,

    Please find attached a working project demonstrating the same approach. You can compare it to yours and see the differences.

    Kind regards,
    Simeon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. jim
    jim avatar
    7 posts
    Member since:
    Nov 2007

    Posted 03 Feb 2008 Link to this post

    thanks for your application. i try it on my machine, it works fine.
    but when i seperate the webservice in another application. it does not work.

    can you give me an solution which the webservice loacated in another application?

    thanks
  13. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 07 Feb 2008 Link to this post

    Hi jim,

    Thank you for  your feedback.

    Due to security reasons, the cross-domain call to a WebService is not allowed from the browser. This is a major issue when using remote WebServices, so we are working on a complete solution to it. We will follow up when we are ready.

    Thank you for your understanding and patience with us.

    All the best,
    Simeon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  14. Telerikuser
    Telerikuser avatar
    35 posts
    Member since:
    May 2009

    Posted 21 May 2009 Link to this post

    Hi Telerik team,

    Is this issue resolved? I mean calling the remote web service from the tree view to load the child on demand solved? I want to call the web service located on a remote server to load the child nodes on demand basis. Please let me know if it is possible?

    Thanks
  15. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 22 May 2009 Link to this post

    Hi subi,

    Unfortunately implementing built-in support for cross domain web services is not possible. There is a built-in restriction in ASP.NET web services which disallows using of JSONP (which is the common solution to do cross domain web service requests). Workarounds do exist however they require writing a custom HTTP handler or using WCF. Still RadTreeView will not be able to automatically use that custom web service (or handler) and should be populated by hand using the client side API.

    All the best,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  16. Akber Ali
    Akber Ali avatar
    7 posts
    Member since:
    Oct 2009

    Posted 05 Oct 2009 Link to this post

    Dear Friend -

    First this link is not working.

    Next there is need for little more explanation on the IDictionary object - used in the Web Service method. I also find a disconnect in under standing the role of java script and web service call.

    Could you please correct me if i am wrong as following:

    1. When the user click the + sign in the tree a JavaScript method has to be called
    2. This java script method initiate the web service.
    3. The web service complete the execution and returns an array (through some way - i can't figure out where and how?) of nodes and the child nodes are populated.

    This is what I found through debugging. I used a OnClientNodePoppulating JS event.

    looking forward to a response.
Back to Top