« Call Center Recordings Script | Main | I Hate SQL Server »
Tuesday
Aug122014

Minor Updates

I'm finally starting to get back into coding again. I don't know what happened, why I stopped for a month. There are excuses I can find, but why bother? I'm only hurting myself the more I procrastinate. Motivation's always been tough for me. But I'm not here to mope (I swear!).

I recently refactored the code a bit on the directory. C# has a very elegant way of dropping in and out of C# code on HTML pages. The rationale being you can write the HTML like you would if it were a plain Jane, static HTML page, and just drop in little bits of C# where necessary. The problem I was running into when making the directory was there were so many of those C# injection points that the whole thing became a big garbled mess. It worked, but I dreaded ever needing to change something.

The solution I came up with was to do all the data manipulation first, and save it all in variables, then insert those variables. So this chunk of code:

<p>Name:    @{result.first_name + " " + result.last_name}</p>

I can't remember if I actually needed the brackets of if it worked in the HTML because of the space. Anyway, I changed that into these two chunks of code:

@{
displayName = result.first_name + " " + result.last_name;
}

That went up before any of the HTML. Then this became the HTML entry:

<p>Name:    @displayName</p>

Now, admittedly, the name example isn't the greatest as the original version is not terribly complex. They got much worse, but I didn't want to try to illustrate one of the more complex examples here. Suffice it to say that it cut out around 2/3rds of the code that was stuffed in the HTML section, and made all but 2 parts of the directory entry simple, single line HTML with a single C# variable inserted.

I'm still working a little bit on the placement of things, and making sure my changes work for different permutations of employees, names, job roles, etc. Next on the list is going to be a form for adding and modifying directory entries

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (2)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: Best dating sites
    Rich Burns - Journal - Minor Updates
  • Response
    Response: Best dating sites
    Rich Burns - Journal - Minor Updates

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.