Can I declare namespaces in the web.config so that I don't have to write using
statements for each namespace in each of my codebehind files?
views:
79answers:
3
A:
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace="MyNamespaces.NamespaceName" />
</namespaces>
</pages>
</system.web>
</configuration>
MyNamespaces.NamespaceName will be now available for all of your pages in project.
cheers
Marko
2010-07-27 10:13:18
A:
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace="MyNamespace" />
</namespaces>
</pages>
</system.web>
</configuration>
Is this what you're looking for?
Matti Virkkunen
2010-07-27 10:13:27
thanx u for reply.if i declared namespace in web.config under pages<?xml version="1.0"?> <configuration> <system.web> <pages> <namespaces> <add namespace="System.Data" /> <add namespace="System.Text" /> </namespaces> </pages> </system.web> </configuration>how to access in .cs file
kumar
2010-07-27 10:18:08
without declaring again in .cs file
kumar
2010-07-27 10:18:24
@kumar: Oh, this only works for UI code (.ascx files and whatnot) - you'll always need to import the namespaces in .cs files. Automagical importing is a messy VB feature which shouldn't exist anyways, so it's not available for C#.
Matti Virkkunen
2010-07-27 10:20:02
ohh.Is it.thanx for reply
kumar
2010-07-27 10:25:43
@Matti, post your comment again as an answer and @kumar can accept it.
Greg B
2010-07-27 16:11:38
@Greg: This answer was by me...
Matti Virkkunen
2010-07-27 20:10:41
@Matti, but you don't explain that it only works for .as*x files in your answer
Greg B
2010-07-28 09:21:45
A:
You can do this for namespaces or common controls:
<system.web>
<pages>
<namespaces>
<add namespace="The.Namespace" />
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" etc... />
</controls>
</pages>
</system.web>
jwsample
2010-07-27 10:13:50