user1566694
user1566694

Reputation: 1363

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>

Upvotes: 11

Views: 10303

Answers (5)

Jeff
Jeff

Reputation: 522

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.

Upvotes: 0

Resource
Resource

Reputation: 544

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

That would've saved me a good hour.

Upvotes: 0

Samir Varteji
Samir Varteji

Reputation: 31

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" %>

Upvotes: 3

Paul Alan Taylor
Paul Alan Taylor

Reputation: 10680

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.

Upvotes: 20

Mahmoud Farahat
Mahmoud Farahat

Reputation: 5475

instead of

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

use

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

Upvotes: 2

Related Questions