Hi all,
So, I don't have to keep adding the following lines to each of my
code-behind pages:
using System.Data.Sql;
using System.Data.SqlClient;
Is there way in the web.config file to add a setting which will tell each
page to automatically include/use those 2 namespaces?
ASP.NET 2
Thanks,
Brian
re:
!> Is there way in the web.config file to add a setting which will tell
!> each page to automatically include/use those 2 namespaces?
Yes.
The namespaces element defines a collection of import directives to use during
assembly pre-compilation. This attribute corresponds to the @ Import directive
on an ASP.NET page.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<pages>
<namespaces>
<add namespace ="System.IO" />
<add namespace="System.Text"/>
</namespaces>
</pages>
</system.web>
</configuration>
Now, you can use System.IO and System.Text in any page without specifically importing them.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Brian Simmons" <centr
@newsgroup.nospam> wrote in message
news:uST8L$GqHHA.3892@TK2MSFTNGP05.phx.gbl...
> Hi all,
> So, I don't have to keep adding the following lines to each of my code-behind pages:
> using System.Data.Sql;
> using System.Data.SqlClient;
> Is there way in the web.config file to add a setting which will tell each page to automatically
> include/use those 2 namespaces?
> ASP.NET 2
> Thanks,
> Brian
"Juan T. Llibre" <nomailrepl
@nowhere.com> wrote in message
news:%23m4483HqHHA.3660@TK2MSFTNGP04.phx.gbl...
> re:
> !> Is there way in the web.config file to add a setting which will tell
> !> each page to automatically include/use those 2 namespaces?
> Yes.
> The namespaces element defines a collection of import directives to use
> during
> assembly pre-compilation. This attribute corresponds to the @ Import
> directive
> on an ASP.NET page.
OTOH, you might consider separating your data access from your pages. The
need to reference SQL Server from so many pages may be considered a mild
hint.
--
John Saunders [MVP]
-----------------------------------------------Reply-----------------------------------------------
re:
!> OTOH, you might consider separating your data access from your pages. The
!> need to reference SQL Server from so many pages may be considered a mild hint.
Indeed...
Whenever I need to do data access, I compile an assembly which I can reference in any page.
Doing that makes code much more manageable.
;-)
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
news:uLHflZIqHHA.4692@TK2MSFTNGP03.phx.gbl...
> "Juan T. Llibre" <nomailrepl
@nowhere.com> wrote in message
>
news:%23m4483HqHHA.3660@TK2MSFTNGP04.phx.gbl...
>> re:
>> !> Is there way in the web.config file to add a setting which will tell
>> !> each page to automatically include/use those 2 namespaces?
>> Yes.
>> The namespaces element defines a collection of import directives to use during assembly
>> pre-compilation. This attribute corresponds to the @ Import directive on an ASP.NET page.
> OTOH, you might consider separating your data access from your pages. The need to reference SQL
> Server from so many pages may be considered a mild hint.
> --
> John Saunders [MVP]