How can I import a .ascx file into a .aspx page using tag registering?

Matt picture Matt · Jun 14, 2009 · Viewed 17.3k times · Source

I have this set up...

<%@ Register TagPrefix="UserControl" 
             TagName="UserLogin" 
             Src="~/admin/Authentication/Login.ascx" %>
<%@ Register TagPrefix="UserControl"
             TagName="UserRegister"
             Src="~/admin/Authentication/Register.ascx" %>

Then later on in the same file I use the tags...

<div id="LoginContainer"><UserControl:UserLogin runat="server /></div>
<div id="RegisterContainer"><UserControl:UserRegister runat="server" /></div>

And for some reason, the UserControl:UserRegister gets underlined in green, when I hover over it, it says "Element 'UserRegister' is not a known element. This can occur if there is a compilation error in the website or if the web.config file is missing."

Is there something else I need to do to make these tags work other than just registering them at the top of the page?

Answer

Amr Elgarhy picture Amr Elgarhy · Jun 14, 2009

No, You did everything.

What you want to make sure from are:

1- Build your project.

2- Make sure there are no errors in the controls.

3- Make sure there is no errors in the web.config.

4- Make sure from the paths you wrote in the Register line that it points to the right controls.

And try to run the web page, may be VS cache something and keeps it green underlined, so try to see the page in run mode.