ASP.NET: Nested Web.config files in conflict

If you have a child app configured in IIS, and you don’t want the web.config of the parent application to affect your child app, here is how you tell the parent app’s config file to go chill down by the river alone. Example: blah.com/web.config

Confessions of a dummy: partial classes

So I am really dumb sometimes. Other times it is my obliviation to the obvious, otherwise known as true ignorance and unexplored knowledge, but certain things CAN be done in code that are allowed but should not be done. For example, there should only be one public partial class per page (as far as I [...]

Crystal Reports/ASP.NET: Fix images not appearing on your reports

When the images won’t appear on your reports and you can’t get them back, try this code. It worked for me. Basically, this tells dotnet to use the Crystal Reports image viewer to get the image and use it on the report. You’ll need to put this is the section of your web.config file. You [...]

ASP.NET: Fix the aspx.designer.cs file when corrupted

For some reason I am coding away and inexplicably, usually when trying to update my Subversion repository, the aspx.designer.cs file that is attached to my page simply decides to ignore all my controls. Perhaps a guru who knows why could explain in the comments, and I am just ignorant. I wouldn’t argue that with you. [...]

ASP.NET C#: Check to see if Session variable exists

Test to see if it DOES exist if(Session["Name"]!=null){ // It does exist, so do stuff! } OR test if it DOESN’T exist if(Session["Name"]==null){ // It doesn’t exist! }

ASP.NET C#: DataTable Compute

If you want to perform a sum or count on the records in a DataTable, you can, very simply. You’ll have to have a DataTable with something in it, like results from a database, then you do this: // my DataTable is full of customer data and is named "dt" object newCustomerCount = dt.Compute("count(id)","CustomerID > [...]

ASP.NET C#: Label Text

To set the text, or displayed value of a Label Control in ASP.NET, do this: lblName.Text = "Ryan"; One thing to note is how to name label controls, with a prefix of “lbl” which helps you identify the type of control anywhere in the code. Also, if you are going to be using a variable [...]

ASP.NET C#: Random GUID

This accepts a GUIDW length parameter and will return the random GUID, sans hyphens, ready for appendage to your filename, string, or other random use. Enjoy! Courtesy of 4guysfromrolla.com public string GetRandomPasswordUsingGUID(int length) { // Get the GUID string guidResult = System.Guid.NewGuid().ToString();   // Remove the hyphens guidResult = guidResult.Replace("-", string.Empty);   // Make sure [...]

ASP.NET C#: using System

At the top of the .cs file (code behind) you will see a list of using statements, which act almost like includes, and provide functions from the specified file being used. For example, the oft used ArrayList collection object is part of the System.Collections namespace. Without the directive used here below, you won’t be able [...]

ASP.NET C#: Using DataTable

To auto-close a datatable after it is done being used (as well as creating a DataTable), a using statement is most helpful. using (DataTable dt = new DataTable()){ //your datatable specific code here }