locked
Custom WebControl: The file 'src' is not a valid here because it doesn't expose a type. RRS feed

  • Question

  • User1397217187 posted

    When trying to use a very simple custom web control (derived from WebControl):

    "The file 'src' is not a valid here because it doesn't expose a type."


    .aspx file:


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestWeb.WebForm1" %>
    <%@ Register TagPrefix="test" TagName="TestWebControl" Src="~/CustomWebControls/TestWebControl.cs" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    		Here is the custom web control: <test:TestWebControl runat="server"/>
        </div>
        </form>
    </body>
    </html>


    Custom control file /CustomWebControls/TestWebControl.cs

    Custom control file ~/CustomWebControls/TestWebControl.cs

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace CustomWebControls
    {
    	public class TestWebControl : WebControl
    	{
    		protected override void Render(HtmlTextWriter output) {
    			output.WriteLine("<div>TestWebControl.Render</div>");
    		}
    	}
    }
    


    Friday, September 18, 2009 11:20 AM

Answers

  • User-1226263862 posted

    It appears your markup is incorrect, try using the ascx or aspx file you have associated with the .cs file.  Also, code behind files have this naming standard PageName.aspx.cs vs. the PageName.cs you have.

    <%@ Register TagPrefix="test" TagName="TestWebControl" Src="~/CustomWebControls/TestWebControl.aspx" %> 


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 19, 2009 9:50 AM