markzzz markzzz - 12 days ago 6
C# Question

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?

Answer

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.

Comments