markzzz
markzzz

Reputation: 47945

How can I use the "using" directive in a .ascx?

I'm bored, on writing C# code on .ascx, to use this syntax :

<%    
     foreach (OriginalPackage.MyPack in OriginalPackage.MyPacks) {
     }
%>

instead of

     foreach (MyPack in MyPacks) {
     }

writing the right using OriginalPackage;

So, is there a way to use the using on the .ascx?

Upvotes: 2

Views: 5778

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1500575

I haven't written an ascx file myself, but this documentation suggests you want:

<%@ Import namespace="OriginalPackage" %>

Upvotes: 6

Oded
Oded

Reputation: 499002

Use the @import directive instead:

<%@ Import namespace="OriginalPackage" %>

Explicitly imports a namespace into an ASP.NET application file (such as a Web page, a user control, a master page, or a Global.asax file), making all classes and interfaces of the imported namespace available to the file. The imported namespace can be part of the .NET Framework class library or a user-defined namespace.

Upvotes: 16

Related Questions