Category Archives: C#

Control Stretching Textboxes, Beyond 100%

asp.net

In ASP.NET I have created a form inside of a fixed width table, and added css to make my textboxes 100% width. For some reason, a long value assigned on the server side was stretching my textbox way past the the defined width of the table cell.

Initial Code:

Title

Solution:
Wrap the textbox inside a div with relative position, then give the textbox an absolution position.

Title

Accessing the web.config from a DLL

asp.netSometimes your website (or a site someone else made)  will include a DLL that interface with your site.  In a recent project, I encountered an issue where the DLL needed to utilize the web.config to access the database. With a quick search, I encountered many others with the same problem. There was a few solutions, but none of them work out of the box. With a little tweaking I was able to make it work.

In the web.config we have our connectionString:

<connectionStrings>
MyDBConnection" connectionString ="server=localhost;database=MyDB; user id=username; pwd=password"/>
</connectionStrings>

And to access it from the DLL:

string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyDBConnection"].ToString();

And finally what they all missed:

Right-Click on your DLL project and Add a Reference to System.Configuration

All solutions that I found said to simply add the ref to the page “using System.Configuration”, which did not work.