+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / XmlDataSource in UserControl not loading

XmlDataSource in UserControl not loading

4 posts, 1 answered
  1. Al
    Al avatar
    1 posts
    Registered:
    13 Jul 2009
    14 Jun 2011
    Link to this post
    I have a very simple user control with an xmldatasource that binds to a repeater which looks something like:

    XmlDataSource xmlFeed = new XmlDataSource();
    xmlFeed.DataFile = "http://www.example.com/books.xml";
    xmlFeed.CacheDuration = 900;
     
    rp.DataSource = xmlFeed;
    rp.DataBind();


    Running the .ascx file on a test.aspx page loads fine and outputs the list of items. For some reason in Sitefinity 4.1 as a usercontrol which I have added to the toolbox it won't load any items from the xml feed.

    Is there anything special that I need to do to make this work?

    Also, I can't seem to find any documentation online about what the "XML Data Source" widget in the Data tool box does.

    Thanks,
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    05 Dec 2016
    16 Jun 2011
    Link to this post
    Hi Al,

    I have created such control that reads xml feeds, rss feeds and also xml files placed in App_Data with minor changes. Please refer to the code I hope it will help you.
    The .ascx file:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="XML.ascx.cs" Inherits="SitefinityWebApp.Custom.XML" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <asp:XmlDataSource ID="XmlDataSource1" runat="server">
     
    </asp:XmlDataSource>
     
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
     
    <ItemTemplate>
    <%#XPath("link")%>"> <%#XPath("title")%>
     
    </ItemTemplate>
     
    <SeparatorTemplate>
     
    <hr />
    </SeparatorTemplate>
     
    </asp:Repeater>
    Code behind:
               XmlDataSource1.XPath = "rss/channel/item";
               XmlDataSource1.Data= "XmlDataSource1";
               XmlDataSource1.DataBind();

    There is no documentation on "XML Data Source" widget currently available. I will address this to the team at the meeting tomorrow. Thank you for the important reminder.

    If you have any problems with this issue please write back.

    Greetings,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. John
    John avatar
    26 posts
    Registered:
    10 Sep 2012
    26 Nov 2012 in reply to Stanislav Velikov
    Link to this post
    Hi Stanislav,

    Has there been any word from Sitefinity about documentation with the XML widget? I am trying to find resources regarding this, but I am coming up short.

    I'm new to .NET and Sitefinity itself, so I am somewhat lost on your post. I did create the .ascx file, and I have my xml file. However, I have 2 follow-up questions:

    1. For the .cs codebehind, where does your code specifically go? Visual Studio adds start-up code, and I'm not sure where to place the XmlDataSource1.DataFile code.

    2. With this code established, how do I connect this data with the XML Data Source widget in Sitefinity? What settings do I use in the dialog box window after a drag out of the widget onto my page?

    I would appreciate any help anyone can offer. Thank you so much,

    Maria
  4. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    05 Dec 2016
    26 Nov 2012
    Link to this post
    Hello Maria,

    There is no documentation on XML Data source control as its just standard XmlDataSource ASP.NET control registered in Sitefintiy.
    It is a lot more easier to use the asp.net XmlDataSource to address scnarious where you need to get xml data displayed as in the sample control from my previous reply.

    To use XmlDataSource sitefinity widget place it on a page and give when editing it give it some ID meaningfull to you.
    Second create user control and when you need access to XMl data put the ID of the XmlDataSource control as datasource.

    This is just saving you the usage of XmlDataSource
    <asp:XmlDataSource ID="XmlDataSource1" runat="server">
      
    </asp:XmlDataSource>

    1. In visual studio when you create new WebUserControl you have a file with an extension .ascx and under this file you can see another one with extension .ascx.cs in the .ascx.cs file paste the code
    namespace SitefinityWebApp
    {
        public partial class TestWebForm : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
            {
               XmlDataSource1.XPath = "rss/channel/item";
               XmlDataSource1.Data= "XmlDataSource1";
               XmlDataSource1.DataBind();
    }
    }

    2. When you drag the control on the page you don`t need to do any settings. Register the user control in Sitefintiy following this documentation (refer to this documentation for a complete sample of creating user controls in Sitefinity).

    Regards,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 1 answered