user control not rendering content of ascx
Asked Answered
H

5

11

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>
Hardigg answered 27/11, 2012 at 16:28 Comment(1)
And what's wrong? No output at all? Empty output (I mean all the wrapper elements are there, but no text inside them)?Hasbeen
S
20

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.

Salome answered 27/11, 2012 at 16:37 Comment(1)
Thank you. That was it. No Src. It turns out the other solution is to drag the ascx page from the solution explorer to the page in design mode and let vs rewrite the declaration. If I wasnt so paranoid about letting vs write code I might've tried that sooner, but I was using vs 2003 the other day and I still get chills...Hardigg
T
3

IF you have created custom control then you should add reference of the dll of your custom control ( from choose items from ToolBox of Visual Studio). and then Use the following tag in the page :

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

If you created User Control then add the following line in your page:

<%@ Register src="~/UserControls/ctrl.ascx" TagName="ctrl" tagprefix="cc1" %>

Toussaint answered 27/11, 2012 at 16:51 Comment(0)
R
2

instead of

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

use

 <%@ Register  src="~/UserControls/ctrl.ascx"  TagName="ctrl" tagprefix="cc1" %>
Rica answered 27/11, 2012 at 16:36 Comment(0)
S
0

Make sure you haven't set visible="false" on a panel or div containing your control.

That would've saved me a good hour.

Sayce answered 13/6, 2016 at 16:29 Comment(0)
P
0

I had to add a new user control to an existing project that already contained a lot of them, and wondered why mine was not rendering. Turns out you can also specify this in Web.config, under configuration, system.web, pages, like this:

<controls>
    <add tagPrefix="cc1" tagName="ctrl" src="~/UserControls/ctrl.ascx" />

...which will register the control for the whole project, so you don't have to specify this on every page. Useful for controls that are heavily reused.

Platte answered 6/6, 2018 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.