By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,969 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,969 IT Pros & Developers. It's quick & easy.

Is there a way to do this with web.config?

P: n/a
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
Jun 6 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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 español : http://asp.net.do/foros/
======================================
"Brian Simmons" <ce******@newsgroup.nospamwrote in message
news:uS**************@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

Jun 6 '07 #2

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@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]
Jun 6 '07 #3

P: n/a
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 español : http://asp.net.do/foros/
======================================
"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@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]


Jun 6 '07 #4

P: n/a
Yes, John, isn't that the beauty of programming, you have choices in the way
_you_ want to do things. And neither is "right" or "wrong", it's whatever
works for _you_ and your client.

I asked a simple question, thanks for the answer I was looking Juan.

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@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]


Jun 7 '07 #5

P: n/a
re:
thanks for the answer I was looking Juan
You're quite welcome, Brian.

As it happened, just last week I had to research that,
so the timing on your question was impeccable.

;-)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Brian Simmons" <ce******@newsgroup.nospamwrote in message
news:OI**************@TK2MSFTNGP03.phx.gbl...
Yes, John, isn't that the beauty of programming, you have choices in the way _you_ want to do
things. And neither is "right" or "wrong", it's whatever works for _you_ and your client.

I asked a simple question, thanks for the answer I was looking Juan.
"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
>"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@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]



Jun 7 '07 #6

P: n/a

Yes there are choices, but most certainly there are some wrong
choices.

Unless you're talking about a one-time-use prototype that you're going
to throw away in a week, I'd agree with John that the db code should
be separate from the aspx code.

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Thu, 7 Jun 2007 09:24:23 -0400, "Brian Simmons"
<ce******@newsgroup.nospamwrote:
>Yes, John, isn't that the beauty of programming, you have choices in the way
_you_ want to do things. And neither is "right" or "wrong", it's whatever
works for _you_ and your client.

I asked a simple question, thanks for the answer I was looking Juan.

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
>"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@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]

Jun 7 '07 #7

P: n/a
Yes there are choices, but most certainly there are some wrong
choices.
Your opinion Sam and let's leave it at that.

I asked a simple question, got my answer, and am moving on.

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:9u********************************@4ax.com...
>
Yes there are choices, but most certainly there are some wrong
choices.

Unless you're talking about a one-time-use prototype that you're going
to throw away in a week, I'd agree with John that the db code should
be separate from the aspx code.

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Thu, 7 Jun 2007 09:24:23 -0400, "Brian Simmons"
<ce******@newsgroup.nospamwrote:
>>Yes, John, isn't that the beauty of programming, you have choices in the
way
_you_ want to do things. And neither is "right" or "wrong", it's whatever
works for _you_ and your client.

I asked a simple question, thanks for the answer I was looking Juan.

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
>>"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@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]


Jun 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.