This is a migrated thread and some comments may be shown as answers.

Web Serivce return null

15 Answers 169 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jason Lee
Top achievements
Rank 1
Jason Lee asked on 14 Jan 2008, 03:10 AM
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?


15 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 14 Jan 2008, 08:41 AM
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
0
Jason Lee
Top achievements
Rank 1
answered on 16 Jan 2008, 01:43 AM
Dear Nick,

Sure....I will use empty node....
Thank you
0
Josemilo
Top achievements
Rank 1
answered on 23 Jan 2008, 10:11 AM
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
0
Simon
Telerik team
answered on 23 Jan 2008, 02:43 PM
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
0
Josemilo
Top achievements
Rank 1
answered on 24 Jan 2008, 09:15 AM
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

0
Simon
Telerik team
answered on 25 Jan 2008, 02:43 PM
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
0
jim
Top achievements
Rank 1
answered on 30 Jan 2008, 04:17 AM
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?
0
Simon
Telerik team
answered on 30 Jan 2008, 12:32 PM
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
0
jim
Top achievements
Rank 1
answered on 30 Jan 2008, 10:41 PM
yes, the webservice is visible from http://localhost/WebSite1/testwebservice.asmx and all the webmethod works fine from that location.
0
Simon
Telerik team
answered on 01 Feb 2008, 09:28 AM
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
0
jim
Top achievements
Rank 1
answered on 04 Feb 2008, 03:08 AM
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
0
Simon
Telerik team
answered on 07 Feb 2008, 09:44 AM
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
0
Telerikuser
Top achievements
Rank 1
answered on 22 May 2009, 01:44 AM
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
0
Atanas Korchev
Telerik team
answered on 22 May 2009, 11:41 AM
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.
0
Akber Ali
Top achievements
Rank 1
answered on 06 Oct 2009, 01:19 AM
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.
Tags
TreeView
Asked by
Jason Lee
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Jason Lee
Top achievements
Rank 1
Josemilo
Top achievements
Rank 1
Simon
Telerik team
jim
Top achievements
Rank 1
Telerikuser
Top achievements
Rank 1
Atanas Korchev
Telerik team
Akber Ali
Top achievements
Rank 1
Share this question
or