Skip to main content
edited tags
Link
Mark Cassidy
  • 25.4k
  • 7
  • 59
  • 117
Source Link

webforms editable sc: fields not rendering

I'm working in a webforms project and I'm trying to add fields that are editable in Experience Editor but they're not showing up on the page. I'm basing this off of other pages that currently implement this and I can't figure out what I'm missing.

aspx:

<%@ control language="C#" autoeventwireup="true" codebehind="Promo.ascx.cs" inherits="MyProject.Promo" %>
<%@ Register Assembly="Sitecore.Kernel" Namespace="Sitecore.Web.UI.WebControls" TagPrefix="sc" %>

<div class="dekalb-promo">
    <div class="wrapper" runat="server" id="divPromo">
        <span class="title">
            <asp:Literal runat="server" ID="litTitle"></asp:Literal>
            <sc:Image ID="imgTitleImage" Field="Title Image" runat="server" />
            <sc:Text ID="txtTitle" Field="Title" runat="server" />
        </span>
        <span class="body">
            <sc:Text ID="txtBody" Field="Description" runat="server" />

        </span>
        <span class="lrn-more">
            <sc:Link ID="linkLrnMore" Field="Link" runat="server" />
        </span>
    </div>
</div>

aspx.cs:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Glass.Mapper.Sc;
using Glass.Mapper.Sc.Web.Ui;
using Sitecore.Diagnostics;
using WebControl = Sitecore.Web.UI.WebControl;
using Sitecore.Globalization;

namespace MyProject
{
    public partial class Promo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var item = ContentHelper.GetContextItem(((WebControl)Parent).DataSource);
            IDekalb_Promo datasource = item.GlassCast<IDekalb_Promo>();
            if (datasource == null) return;

            divPromo.Attributes[Consts.HTML_ATTRIBUTE_STYLE] = "background-image: url('" + datasource.Background_Image?.Src + "')";
            if (datasource.Title_Image != null && !String.IsNullOrEmpty(datasource.Title_Image.Src))
            {
                litTitle.Text = "<img class='title-img' src='" + datasource.Title_Image.Src + "'></img>";
            }

            if (!Sitecore.Context.PageMode.IsExperienceEditor)
            {
                imgTitleImage.Visible = false;
            }

            if (datasource.Link == null || String.IsNullOrEmpty(datasource.Link.Url))
            {
                linkLrnMore.Visible = false;
            }
        }
    }
}