Search code examples
c#user-controls

user control not rendering content of ascx


i thought this was a simple issue until i started searching for answers and realised it's so simple i'm the only one who has it

my user control isnt displaying anything. what am i doing wrong? (besides letting this be my life...)

control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ctrl.ascx.cs" Inherits="proj.UserControls.ctrl" %>

asdjkldasfjasdfljdfasjklasdfjkl

use:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="page.aspx.cs" Inherits="proj.Admin.page" %>

<%@ Register assembly="proj" namespace="proj.UserControls" tagprefix="cc1" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <cc1:ctrl ID="test" runat="server" />
</asp:Content>

Solution

  • Change:-

    <%@ Register assembly="proj" namespace="proj.UserControls" tagprefix="cc1" %>
    

    To

    <%@ Register TagPrefix="cc1" TagName="ctrl" Src="/path/to/ctrl.ascx" %>
    

    You're missing TagName, which represents the text following the colon in the control declaration. You're also not telling the engine where to find the source file ( Src attribute ). Change /path/to to represent the path from root to your control.