Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference Web.Config from a Control Library

Status
Not open for further replies.

VergeResources

Programmer
Feb 6, 2002
40
US
I have created a control library that requires database access. I do not want to pass a connectionstring to every object - I want them to be able to access the settings in the web.config. Is there a way to do this? ConfigurationManager does not exist within a control library. Thanks in advance!
 
Why do you mean by control library? Do you have a WebUsercontrol(s) that you want to access the web.config from?

JIm
 
My solution has two projects. One project is just a control library, the second is a web project. All my controls within the web project inherit from controls in the control library (so I can share functionality).

Problem is when I want to move database actions up into the base control... the control library cannot access the web.config in the web project.
 
Oh - Basically every type of control I can put on a web page. I have base controls for textbox, dropdownlist, button, etc.
 
Since you are creating custom controls, I don't know how you would do what you want. What you can do, is to create a data access layer, using a class or classes. Then you can just instantiate the class(s) on the page where you need DB access and use them.

Jim
 
As your control library project is in the same solution as that of the web project so you should be able to access the web.config of the web project as its common to the entire solution. Like for example

It should work if you write this in your control library .cs file
System.Configuration.ConfigurationSettings.AppSettings["DBConnectionString"];

Let me know what you get with the above statement. Also let me know how many web.config files your solution has.

Manish
 
Thanks for the tip. I actually found a way around my issue. Basically, I put an overrideable ConnectionString property in my Base Master page (in my control library). Then, in my web project, I inherited from this Master Page and overrode the property to return a string from the webconfig. Now, all my web control library controls just ask their master page for the connectionstring. Works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top