Error loading the WebPart, Custom WebPart not Loading

Mike Bilz asked on November 20, 2020 21:06

Hello Kentico Team,

I have received the dreaded [Error loading the WebPart 'ContactInformation' of type 'ContactInfo'] error. No information about this error appears in the Event Log, and no further information is provided anywhere else about what precisely the issue is.

I built this WebPart by copying an existing custom WebPart and adding new fields and content.

ASCX:


<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_LACC_ContactInfo"  CodeFile="~/CMSWebParts/LACC/ContactInfo.ascx.cs" %>
<div class="pageWidth">
    <div class="contactInfoHolder clearfix">
        <div class="contactInfoItem oneFifthWidth">
            <asp:Panel ID="MeetingButton" runat="server" class="contactInfoLink"><asp:HyperLink ID="MeetingLink" Target="_blank" ToolTip="Schedule a Meeting" runat="server"/></asp:Panel>
        </div>
        <div class="contactInfoItem oneFifthWidth">
            <asp:Panel ID="LiveChatButton" runat="server" class="contactInfoLink"><asp:HyperLink ID="LiveChatLink" Target="_blank" ToolTip="Live Chat and Support" runat="server"/></asp:Panel>
        </div>
        <div class="contactInfoItem oneFifthWidth">
            <asp:Panel ID="EmailButton" runat="server" class="contactInfoLink"><asp:HyperLink ID="EmailLink" Target="_blank" ToolTip="Email this Department" runat="server"/></asp:Panel>
        </div>
        <div class="contactInfoItem oneFifthWidth">
            <asp:Panel ID="LobbyButton" runat="server" class="contactInfoLink"><asp:HyperLink ID="LobbyLink" Target="_blank" ToolTip="Drop-in Lobby" runat="server"/></asp:Panel>
        </div>
        <div class="contactInfoItem oneFifthWidth">
            <asp:Panel ID="LobbyText" runat="server" class="contactInfoText"><asp:Literal ID="LobbyHours" runat="server"/></asp:Panel>
        </div>

    </div>
    <asp:HyperLink ID="WebsiteLink" Target="_blank" runat="server" CssClass="redButton zButton"/>

ASCX.CS:


using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CMS.PortalControls;
using CMS.Helpers;

public partial class CMSWebParts_LACC_ContactInfo : CMSAbstractWebPart
{
    #region "Properties"

    public string DepartmentNameVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("DepartmentName"), "");
        }
        set
        {
            this.SetValue("DepartmentName", "");
        }
    }
    public string MeetingLinkVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("MeetingLink"), "");
        }
        set
        {
            this.SetValue("MeetingLink", "");
        }
    }
    public string LiveChatLinkVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("LiveChatLink"), "");
        }
        set
        {
            this.SetValue("LiveChatLink", "");
        }
    }
    public string EmailLinkVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("EmailLink"), "");
        }
        set
        {
            this.SetValue("EmailLink", "");
        }
    }
    public string LobbyLinkVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("LobbyLink"), "");
        }
        set
        {
            this.SetValue("LobbyLink", "");
        }
    }
    public string LobbyHoursVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("LobbyHours"), "");
        }
        set
        {
            this.SetValue("LobbyHours", "");
        }
    }
    public string WebsiteLinkVar
    {
        get
        {
            return ValidationHelper.GetString(this.GetValue("WebsiteLink"), "");
        }
        set
        {
            this.SetValue("WebsiteLink", "");
        }
    }


    #endregion


    #region "Methods"

    /// <summary>
    /// Content loaded event handler.
    /// </summary>
    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();
    }


    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            MeetingLink.NavigateUrl = MeetingLinkVar;
            MeetingLink.Text = "Schedule a Meeting with " + DepartmentName + "";
            LiveChatLink.NavigateUrl = LiveChatLinkVar;
            LiveChatLink.Text = "Live Chat with " + DepartmentName + "";
            EmailLink.NavigateUrl = "mailto: " + EmailLinkVar + "";
            EmailLink.Text = "Email " + DepartmentName + "";
            LobbyLink.NavigateUrl = LobbyLinkVar;
            LobbyLink.Text = "Visit the " + DepartmentName + "Drop-In Lobby";
            LobbyHours.Text = LobbyHoursVar;
            WebsiteLink.NavigateUrl = WebsiteLinkVar;
            WebsiteLink.Text = "Visit the " + DepartmentName + " Website";
        }
    }


    /// <summary>
    /// Reloads the control data.
    /// </summary>
    public override void ReloadData()
    {
        base.ReloadData();

        SetupControl();
    }

    #endregion
}

Any assistance would be greatly appreciated.

Thanks. -mike

Correct Answer

Brenden Kehren answered on December 4, 2020 15:28

Mike,

The issue is as I initially stated, plus another one I discovered. I created your control in a v10 instance and found these issues:

Replace:
using CMS.PortalControls;
With
using CMS.PortalEngine.Web.UI;

Fix your property names
public string DepartmentNameVar{}
MeetingLink.Text = "Schedule a Meeting with " + DepartmentName + "";
Notice you're tying to assign the property DepartmentName which doesn't exist. Although DepartmentNameVar does.

Lastly, you may want to actually build your project in Visual Studio and you'll find these errors with improper using statements. You can have all the incorrect code you want on your website but until you actually build it or use the code you have incorrect references to, it won't break. Plus using a tool like Visual Studio will allow you to visually see errors immediately and avoid issues like this.

Error 1

Error 2

1 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on November 20, 2020 21:14

How did you copy the Web Part? From the Admin interface or manually?

Can you confirm the code behind reference is correct:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_LACC_ContactInfo" CodeFile="~/CMSWebParts/LACC/ContactInfo.ascx.cs" %>

Could it be it references the OLD code file instead of your new one?

0 votesVote for this answer Mark as a Correct answer

Mike Bilz answered on November 20, 2020 21:29

Hi David,

The code files were manually copied and edited before uploading to the site, then the custom WordPart was created in Kentico linking to the new files.

The file names are ContactInfo.ascx and ContactInfo.ascx.cs and the files are in the appropriate folder.

Thanks. -mike

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 20, 2020 21:30 (last edited on December 4, 2020 16:07)

No sure what version you're on but in v10, v11, and v12 you need a using statement for the CMS.PortalEngine.Web.UI dll.

0 votesVote for this answer Mark as a Correct answer

Mike Bilz answered on November 20, 2020 23:48

Hi Brenden,

I am using version v10.0.26, and none of my other custom WebParts have the PortalEngine call.

This is extremely perplexing because the code behind file is identical to all of my other custom WebParts, and yet this one is throwing an error.

Could this be as simple as a syntax error? Or maybe a step I missed on the Portal Engine side?

Thanks.

-mike

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 21, 2020 03:54 (last edited on November 23, 2020 16:29)

If you're using a web app you'll need to build it and redeploy that dll. If you're using a website you can just deploy that .cs file.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on November 23, 2020 10:35 (last edited on November 23, 2020 20:35)

Could you please double-check the version you are using? I am asking because the CMS.PortalControls was removed in Kentico 10 and replaced by CMS.PortalEngine.Web.UI - so, in Kentico 10 you should be using it. Also, the CMSAbstractWebPart class is part of the new namespace. Are you able to build the code in Visual studio with no errors? I just copied your code (I just changed the file name and replaced CMS.PortalControls with CMS.PortalEngine.Web.UI) and it is working fine. I am getting the list if links (sample screen shot) and no errors.

0 votesVote for this answer Mark as a Correct answer

Mike Bilz answered on December 4, 2020 00:16

Hi Juraj,

I made the changes you suggested, and even tried starting over with new files generated by Kentico, and I am still receiving that same error. Are there any other changes that you made to your working file to get the working result you achieved?

I am not using Visual Studio to make these files, but that was never an issue before.

Any assistance you can provide would be greatly appreciated.

Thanks. -mike

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 4, 2020 07:29

I have not made any other changes. I would try running the project in Visual studio, clean the solution and then build it. Also, I would try clearing the .Net temporary cache files (c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files)

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 4, 2020 15:37

You are right, Brenden, I forgot that I changed the DepartmentName property. But I also assumed that Mike checked the Event log, where the wrong variable is logged, so I thought this was already fixed (sample Event log detail). So, I focused on something more complex. Lesson learnt! Thanks.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.