Bryan B
Bryan B

Reputation: 4535

Why are my ASP.NET webforms controls not rendering?

I have a feeling I'm missing one small thing. I have very simple page, created from the ASP.NET templates in VS2010. My Default.aspx consists of simply the following code. The Site.Master page is doing what it's supposed to.

<%@Page 
    Title="Home Page" 
    Language="C#" 
    MasterPageFile="~/Site.master" 
    AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" 
    Inherits="UserControlTest._Default" %>

<%@Register 
    TagPrefix="tsi" 
    Namespace="UserControlTest.Controls" 
    Assembly="UserControlTest" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <!-- HERE BE DRAGONS -->
    <tsi:BigHelloBanner   runat="server" />
    <tsi:SmallHelloBanner runat="server" />

</asp:Content>

BigHelloBanner contains this:

<%@Control 
    Language="C#" 
    AutoEventWireup="true" 
    Visible="true"
    CodeBehind="BigHelloBanner.ascx.cs" 
    Inherits="UserControlTest.Controls.BigHelloBanner" %>

<h1>HI!</h1>

Both the codebehind files in both objects are empty, and inherit from UserControl. The behavior is the same inheriting from Control. When I view-source on the rendered output, nothing from the HelloBanners is output, except some newlines. The HERE BE DRAGONS comment is visible, which indicates to me that the master page and all that works fine. I am expecting to see the <h1>HI!</h1> markup in the output as well. What am I missing? This seems really basic.

Upvotes: 0

Views: 3119

Answers (4)

Mark Cidade
Mark Cidade

Reputation: 99957

It looks like that you're referring to the empty code-behind class instead of the ASCX file with the output. Use the src attribute in your @Register directive:

<%@Register 
    TagPrefix="tsi" 
    TagName="BigHelloBanner" 
    Src="BigHelloBanner.ascx" %>

Upvotes: 4

Paolo Falabella
Paolo Falabella

Reputation: 25844

Since BigHelloBanner is a web user control, you should try registering it like this:

<%@Register TagPrefix="tsi" TagName="BigHelloBanner" Src="~/pathToUserControls/BigHelloBanner.ascx" %> 

Upvotes: 2

Bobby
Bobby

Reputation: 1604

I can't see the src attribute here where is your control held ?

<%@Register 
    TagPrefix="tsi" 
    Namespace="UserControlTest.Controls" 
    Assembly="UserControlTest"
    src="?" %>

Upvotes: 2

TheDPQ
TheDPQ

Reputation: 486

Don't you still need to give an ID to each control instance?

Upvotes: 0

Related Questions