views:

130

answers:

2

Hello all,

I created a simple custom control that only inherits from the Literal control, and doesn't have any extensions yet, code is empty.

Namespace: CustomControls

Class name: Literal : System.Web.UI.WebControls.Literal

Next thing I do is registering this control in the aspx page as following:

<%@ Register TagPrefix="web" Namespace="CustomControls" %>

(I read in few tutorials that this is one of the ways to register it, besides web.config etc.)

After all, no intellisence for me, and worse- I get a parse error 'unknown server tag: web' when I try to run the page with the control in it.

I used 'create new project' and not new website, in case this info is needed.

What could be my problem?

Thanks in advance.

A: 

Do it like this:

<%@ Register TagPrefix="sometag" Namespace="Somewhere" Assembly="Somewhere.Project" %>

Then when you type: sometag you should get a list of all valid controls in the "Somewhere" namespace that is contained in the "Somewhere.Project" assembly.

See how u go.

RPM1984
Thanks for the comment,It's not a user control, it's a custom control, and it doesn't have any ascx file, only a .cs class file.
Gal V
sorry - my mistake. i edited my answer.
RPM1984
As I saw in few tutorials, A custom control can be registered also without an assembly reference, Is that true ?
Gal V
It is in the same project under App_Code...
Gal V
Here's two examples where i use the Register prefix in my web application, in the same ASPX page:<%@ Register TagPrefix="foo" TagName="FooBar" Src="~/Controls/FooBar.ascx" %><%@ Register TagPrefix="foo" Namespace="Foo.Model.Controls" Assembly="Foo.Model" %>Think you're getting confused with the use of "Assembly" attribute for user controls (ASCX) and custom controls (CS).Try using both, when when its working - remove the assembly attribute and im pretty sure it will fail.
RPM1984
A: 

You can also register your control in web.config if you would like to use it on other pages

<pages>
        <controls>
          <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add tagPrefix="web" namespace="MyProject.CustomControls" assembly="MyProject" />
        </controls>
      </pages>

For web site this will work

<add tagPrefix ="web" namespace="ASP.App_Code.CustomControls" />
orjan
Thanks for the response,The thing is- I don't have any assembly file yet, and as I understood, the control can be registered by tagprefix and namespace only, even without assembly. am I right ?
Gal V
If you have created a web application project you will have an assembly, see:http://dl.dropbox.com/u/6561262/project-settings.png
orjan