Monthly Archives: March 2012

Example of Why You Shouldn’t Use Hungarian Notation

So today had to go into a project and make a small change from a regular textbox to a Masked Numeric TextBox the control was for Phone Numbers to be used for a contacts object that is gotten and updated throughout the session and used in multiple other places in the web site. problem was is that the hungarian annotation had to be changed through out. Anywhere the object or session object was referenced. Also it was being placed into a local object in other places, so find and replace did not work for all those who were about to shout it. example:

TextBox alter_tbxPhoneNumber = (TextBox)Session["tbxPhoneNumber"];

This broke because the object was no longer a TextBox and therefore you can’t cast it to a TextBox nor can you place it into a TextBox object. If you’re a developer and you can’t mouse over a variable name to see what type it is or simply use getType then object orientation isn’t for you in the first place. Just my opinion though. Till next time don’t let your code have a meltdown.


Posted by on March 16, 2012 in Uncategorized


Using Telerik RadAjaxPanel and RadAjaxLoading Panel

So as some of you know I am all about Telerik Ajax controls when you understand them they save you a great deal of time and can give you some cool features with just a little drag and drop. Add about  60 seconds of typing to set up the controls and bam. As we all know users are sometimes impatient we have gotten them used to instant everything these days on the web and sometimes that’s just not possible.
A few things are going to take a second or 2. This is definitely an issue when using ajax and server request event validation and you get an impatient user who just wants to keep working and not wait on the post back.

Enter RadAjaxPanel and RadLoadingPanel check out the following code snippet

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
	<div class="loading" style=" margin-top:50%; margin-bottom:50%; margin-left:auto; margin-right:auto;">

		<asp:Image ID="Image1" runat="server" ImageUrl="Img/loading44.gif" AlternateText="loading..."/>

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1"
						EnableHistory="True" HorizontalAlign="NotSet">
<!-- Put your content here -->

in the code snippet above I achieve 3 main things instantly with the above code snippet
1. user cannot click on the controls after a post back begins until the post back ends. During that time the loading panel covers the entire RadAjaxPanel until its finished

2. I can display a custom (read Branded) loading gif and if it fails it just says loading.

3 it allows my user to know what is going on, stops them from messing with anything else in the panel, and also allows them to see when to proceed if i just disabled or overlayed the controls the user would become confused or think their browser/website was broken and in come the support tickets.

This takes all of 2 minutes and did i mention it provides instant ajax history without you having to create all the tedium that comes along with that all in 2 simple controls I will post an example site once I get home. Till then don’t let your code have a melt down.

Leave a comment

Posted by on March 13, 2012 in ASP.Net, C#


Tags: , , ,

How Setting Up Web Config Transformation Files can Save you Time and Avoid Deployment Mistakes.

So let’s be honest, even if no one ever noticed because we caught it before the damage was done, We have all deployed a site with the developement connection string still in place. This and things like it happen when you manually set up your web config. Well heres the answer to things like that —

So what is Web Configuration Transformation, for those who don’t want to click yet I will explain. Transformation is a addon item to your web config file that allows you to declare items to be replaced based on the compilation type you set in your build type drop box at the top of your VS(Visusal Studio) IDE. So if I build in Release mode then the Web.Release.Config transformation file kicks in and replaces the values I told it to, in most cases for me this deals with connection strings to databases and names/addresses for web services. This is handy because you can include it in the svn check out and everyone has it so no more pesky ooops I forgot to change my connections just do it once, maintain it, and bam you sir are good to go.

Leave a comment

Posted by on March 12, 2012 in ASP.Net, C#, C# for Beginners


Tags: , ,

find the diffrence between 2 DateTimes in C# (DateDiff for you T-SQL Buffs)

SO many times you need to get the amount of time between 2 dates or you need to validate that the range between DateTimes is not within or beyond a certain amount of seconds,minutes,hours,days,months, and/or years. In T-SQL you get this info with the DateDiff function in c# we don’t have a function persay but the datetime type does have a method you can use to get it here is an example of the subtraction version.

//these are date time controls that we cast the values as date time
                et = (DateTime)EarliestCallDate.SelectedDate;
                lt = (DateTime)LatestCallDate.DbSelectedDate;
// now lets get the diffrence in days
            if (et > lt)
                error.Text = "Earliest Call Date Cannot Be Less Than Latest Call Date.";
            else if (lt.Subtract(et).Days > 1) // right here it is
                error.Text = "Earliest Date and Latest Date must be in the same day";

As you can see it is pretty simple the Return Type of lt.Subtract(et).Days is TimeSpan.Days. Well hopefully this helps someone until next time I post don’t let your code have a meltdown.

Leave a comment

Posted by on March 9, 2012 in C#, C# for Beginners


Tags: ,

My Default Helper Class

Just wanted to post what I have as my default helper class it is small just 2 methods but I use it in almost every project I do. the first one gets your connection string and the other executes a sql sommand that returns a table.

just fill in the catchs with your own error logging/handeling if you wish to do it or just leave it be and return null( I don’t recommend this but you can) and well there you go. use your helper class for any common code snippet you use over and over instead of writing the same thing all the time.

public class Helpers
        /// <summary>
        /// Returns the current connection string
        /// </summary>
        /// <returns></returns>
        public SqlConnection getConnection()
            SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);
            return Con;

        /// <summary>
        /// Returns a DataTable, based on the command passed
        /// </summary>
        /// <param name="cmd">
        /// the SqlCommand object we wish to execute
        /// </param>
        /// <returns>
        /// a DataTable populated with the data 
        /// specified in the SqlCommand object
        /// </returns>
        /// <remarks></remarks>
        public DataTable GetDataTable(SqlCommand cmd)
                // create a new data adapter based on the specified query.
                using (SqlDataAdapter da = new SqlDataAdapter() { SelectCommand = cmd })
                    // create a new DataTable
                    DataTable dtGet = new DataTable();
                    //fill the DataTable
                    //return the DataTable
                    return dtGet;
            catch (SqlException ex)
                return null;
            catch (Exception ex)
                return null;

Leave a comment

Posted by on March 9, 2012 in C#, C# for Beginners