用户控件从3.7迁移到5.2后停止工作

时间:2012-11-23 11:15:53

标签: c# asp.net .net telerik sitefinity

我最近将我的3.7 sp4项目迁移到5.2,但这样做时遇到了问题。 目前,在5.2项目中迁移后,我的用户控件无法正常工作。

以下是代码:

用户控制代码:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SiteMenu.ascx.cs" Inherits="UserControls_Nav_SiteMenu" %>
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
<telerik:RadMenu ID="RadMenu1" runat="server" DataSourceID="SitemapDataSource1" OnItemDataBound="RadMenu1_ItemDataBound">
</telerik:RadMenu>

用户控件的类代码:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Drawing;

using Telerik;
using Telerik.Cms;
using Telerik.Cms.Web;
using Telerik.Web.UI;
using Telerik.Caching;
using Telerik.Cms.Web.UI;


[DefaultProperty("StartingNodeOffset")]
public partial class UserControls_Nav_SiteMenu : System.Web.UI.UserControl, ICacheableObject
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected override void Render(HtmlTextWriter writer)
    {
        // Checks if this is called by the Search Indexer and does not render anything if so.
        // Navigation controls are present in every page and should NOT be indexed multiple times.
        if (!CmsContext.IsRequestCrawler(this.Context))
            base.Render(writer);
    }

    #region Data Fields

    private bool hideUrlForGroupPages = false;
    private string selectedItemCssClass = "selectedItem";

    #endregion

    #region Properties



    [Browsable(true)]
    [Category("Behavior")]
    public int LastExpandLevel
    {
        get
        {
            if (this.RadMenu1.MaxDataBindDepth < 0)
                return 0;
            return this.RadMenu1.MaxDataBindDepth;
        }
        set
        {
            if (value == 0)
                this.RadMenu1.MaxDataBindDepth = -1;
            else
                this.RadMenu1.MaxDataBindDepth = value;
        }
    }


    [Browsable(true)]
    [Category("Behavior")]
    public int ExpandDelay
    {
        get
        {
            return this.RadMenu1.ExpandDelay;
        }
        set
        {
            this.RadMenu1.ExpandDelay = value;
        }
    }


    [Browsable(true)]
    [Category("Behavior")]
    public bool ClickToOpen
    {
        get
        {
            return this.RadMenu1.ClickToOpen;
        }
        set
        {
            this.RadMenu1.ClickToOpen = value;
        }
    }


    [Browsable(true)]
    [Category("Behavior")]
    [DefaultValue(false)]
    public bool HideUrlForGroupPages
    {
        get
        {
            return this.hideUrlForGroupPages;
        }
        set
        {
            this.hideUrlForGroupPages = value;
        }
    }


    [Browsable(true)]
    [Category("Appearance")]
    public string SelectedItemCssClass
    {
        get
        {
            return this.selectedItemCssClass;
        }
        set
        {
            this.selectedItemCssClass = value;
        }
    }


    [Browsable(true)]
    [Category("Appearance")]
    public string CssClass
    {
        get
        {
            return this.RadMenu1.CssClass;
        }
        set
        {
            this.RadMenu1.CssClass = value;
        }
    }


    [Browsable(true)]
    public RadMenu Menu
    {
        get
        {
            return this.RadMenu1;
        }
        set
        {
            this.RadMenu1 = value;
        }
    }


    [Browsable(true)]
    [Category("Navigation")]
    public int StartingNodeOffset
    {
        get
        {
            return this.SiteMapDataSource1.StartingNodeOffset;
        }
        set
        {
            this.SiteMapDataSource1.StartingNodeOffset = value;
        }
    }


    [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms")]
    [Browsable(true)]
    [Category("Navigation")]
    public string StartingNodeUrl
    {
        get
        {
            return this.SiteMapDataSource1.StartingNodeUrl;
        }
        set
        {
            this.SiteMapDataSource1.StartingNodeUrl = value;
        }
    }


    [Browsable(true)]
    [Category("Navigation")]
    public bool StartFromCurrentNode
    {
        get
        {
            return this.SiteMapDataSource1.StartFromCurrentNode;
        }
        set
        {
            this.SiteMapDataSource1.StartFromCurrentNode = value;
        }
    }


    [Browsable(true)]
    [Category("Navigation")]
    public bool ShowStartingNode
    {
        get
        {
            return this.SiteMapDataSource1.ShowStartingNode;
        }
        set
        {
            this.SiteMapDataSource1.ShowStartingNode = value;
        }
    }

    /// <summary>(Exposed from contained RadMenu.)</summary>
    [Browsable(true)]
    [Category("Appearance")]
    public string SkinID
    {
        get
        {
            return this.RadMenu1.SkinID;
        }
        set
        {
            this.RadMenu1.SkinID = value;
        }
    }


    [Browsable(true)]
    [Category("Appearance")]
    public string Skin
    {
        get
        {
            return this.RadMenu1.Skin;
        }
        set
        {
            this.RadMenu1.Skin = value;
        }
    }

    #endregion

    #region Methods

    public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)
    {
    CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode;

        if (this.hideUrlForGroupPages)
        {

            if (node != null)
            {
                // save the PageID in the attributes of the menu item
                e.Item.Attributes.Add("PageID", node.Key);

                if (node.PageType == CmsPageType.Group)
                {
                    e.Item.NavigateUrl = "";
                }

            }
        }

        if (node.CmsPage != null)
        {
            if (node.CmsPage.PageType == CmsPageType.External)
            {
                e.Item.Target = "_blank";
            }
        }
    }

    #endregion

    #region ICacheableObject Members

    public System.Web.Caching.CacheDependency[] GetDependencies()
    {
        CmsSiteMapProvider provider = null;
        if (!String.IsNullOrEmpty(this.SiteMapDataSource1.SiteMapProvider))
            provider = SiteMap.Providers[this.SiteMapDataSource1.SiteMapProvider] as CmsSiteMapProvider;
        else
            provider = SiteMap.Provider as CmsSiteMapProvider;
        if (provider != null)
        {
            return new System.Web.Caching.CacheDependency[]{ provider.CloneCacheDependency()};
        }
        return null;
    }

    #endregion
}

编辑模板时(在管理员模式下),控制位置会显示以下错误:

Both DataSource and DataSourceID are defined on 'RadMenu1'.  Remove one definition. 



Description: An unhandled exception occurred during 
the execution of the current web request. Please review the stack trace 
for more information about the error and where it originated in the 
code.





Exception Details: System.InvalidOperationException: Both DataSource and DataSourceID are defined on 'RadMenu1'.  Remove one definition.



Source Error: 








An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the 
exception can be identified using the exception stack trace below.








Stack Trace: 






[InvalidOperationException: Both DataSource and DataSourceID are defined on 'RadMenu1'. Remove one definition.]
System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView() +3234866
System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e) +28
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.AddedControl(Control control, Int32 index) +11422584
System.Web.UI.Control.EnsureChildControls() +182
System.Web.UI.Control.PreRenderRecursiveInternal() +60
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4201











Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

但我搜索了我的代码,因为你可以看到上面只有DataSourceID被定义。

我该怎么办?

由于

1 个答案:

答案 0 :(得分:0)

此值将位于.aspx页面的HTML中,而不是后面的代码中。检查那里,我在迁移Telerik RadControls版本之前已经看到过这个问题。