ASP.NET C# LINQ Programming


While reading about a recent question concerning @@Identity and the reasons to use SCOPE_IDENTITY() instead I experimented with LINQ to get the SCOPE_IDENTITY() results.

 using (var dbc = new siteDataContext())
        dbc.Log = Console.Out;
        repertoire newSkill = new repertoire
                skill = "a new item"

It seems that calling the id column of the inserted object gives you the SCOPE_IDENTITY(). Here is the SQL Log:

INSERT INTO [dbo].[repertoire]([skill])
VALUES (@p0)
-- @p0: Input NVarChar (Size = 10; Prec = 0; Scale = 0) [a new item]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1

Sweet rhythm section


Music really does set the mood


Web design Web standards

71.5% of screen reader users find Flash difficult to use

WebAIM‘s Screen Reader Survey, conducted December 2008 to January 2009, is a very interesting read. Yet another nail in the Flash coffin but surprisingly Frames are deemed easy to use by nearly 60% of screen-reader users.

Give it a quick look. Comments open.

ASP.NET C# Programming

Adding AJAX to an existing project that includes Routing

I was working on a project and just on a whim decided to try out some of .NET’s AJAX controls. I chose a random page, added a ScriptManager, tossed in a TextBox and a CalendarExtender.

F5. Page shows up. Javascript error:

Line: 121
Char: 1
Error: 'Sys' is undefined
Code: 0
Url: http://localhost:49329/admin.aspx


Try a new project. Add a ScriptManager, tossed in a TextBox and a CalendarExtender. Works fine. Huh?

I go through the Web.Config files of the two. Nothings changed except the version number on everything:

non working: Version=
working: Version=1.0.61025.0

Ah ha! That must be it. I reset the working project as a 3.5 app and run it. I was so sure it was going to fail. Nope. Worked fine.

Must be something else. *grumble*

I start taking pieces out of my existing app and when I came to the Global.asax I took out the RouteTables and AJAX comes to life! FINALLY!

Here is what I had:


		protected void Application_Start(object sender, EventArgs e)
			// Code that runs on application startup
		private static void RegisterRoutes(ICollection<RouteBase> Routes)
				new Route("{Parameter}/{pageID}", new RouteHandler()));
				new Route("{Parameter}", new RouteHandler()));

With my routing handler file showing this little gem:


				string virtualPath = string.Format("~/{0}.aspx", pageName);
				return (Page)BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page));

So basically it was swiping the file extensions from my httpHandlers and replacing them with .aspx meaning they were not found.


			<remove verb="*" path="*.asmx"/>
			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

To handle the situation I added the following to Global.asax:


		protected void Application_Start(object sender, EventArgs e)
			// Code that runs on application startup
		private static void RegisterRoutes(ICollection<RouteBase> Routes)
			RouteTable.Routes.Add(new System.Web.Routing.Route("{resource}.axd/{*pathInfo}",
					   new System.Web.Routing.StopRoutingHandler()));
			RouteTable.Routes.Add(new System.Web.Routing.Route("{service}.asmx/{*path}",
					   new System.Web.Routing.StopRoutingHandler()));
				new Route("{Parameter}/{pageID}", new RouteHandler()));
				new Route("{Parameter}", new RouteHandler()));

I hope this helps. 🙂

ASP.NET Bible tags C# Christianity LINQ Programming

Working on Bible Verse Tags for ASP.NET (C#)

To do:

  • build Regex to detect bible verses in tags
  • put in named back-references
  • find a way to choose different tables with LINQ
  • make it work for an entire chapter
  • add error messages
  • move it to a class file instead of in the page
  • run it from the filterText method if IndexOf(“[bible]”) !=-1
  • fix toVerse in case it goes out of range
  • fix misspelled or abbreviated bookName with value from database
  • change to Compiled Queries
  • add footnotes
  • pretty up error messages
  • clean up final code
public class bibleParts
	public static Func<bibleDataContext, string, IQueryable<bibleParts>>
		theVersion = CompiledQuery.Compile((bibleDataContext context, string bibleVersion) =>
			(from v in context.bibles_infos
			 where v.bibleName == bibleVersion
			 select new bibleParts
					 version = v.bibleID,
					 language = v.language,
					 copyright = v.copyright

	public static Func<bibleDataContext, int, string, IQueryable<bibleParts>>
		theBook = CompiledQuery.Compile((bibleDataContext context, int bookLang, string book) =>
			(from b in context.book_names
			 where ( == book || b.abbreviation == book || b.alt == book) && b.language == bookLang
			 select new bibleParts
				 bookID = b.book_id,
				 book =
	public static Func<bibleDataContext, int, int, int, IQueryable<bibleParts>>
		theVerses = CompiledQuery.Compile((bibleDataContext context, int version, int book, int chapter) =>
			(from v in context.verses
			 where v.versionID == version && v.bookID == book && v.chapter == chapter
			 select new bibleParts
				 verseNum = v.verse1,
				 thisVerse = v.text

	public int version {get;set;}
	public int language {get;set;}
	public string copyright {get;set;}
	public int bookID {get;set;}
	public string book {get;set;}
	public int verseNum {get;set;}
	public string thisVerse {get;set;}
<pre><pre>private string verseMod(string text)
	string textVal = text;
	string errorValue = "";
	string verseNumBegin = "<sup>";
	string verseNumEnd = "</sup>";
	string footerBegin = "<em> - ";
	string footerEnd = "</em>";
	string bibleVersion = "kjv";  //default version if none is specified
	string pat = @"\[bible[=]?(?<version>[a-zäëïöüæø]*)](?<entire>(?<book>([0-9][\s]?)?[a-zäëïöüæø]*[\s]{1}([a-zäëïöüæø]*[\s]?[a-zäëïöüæø]*[\s]{1})?)(?<chapter>[0-9]{1,3})(:{1}(?<verse>[0-9]{1,3})(-{1}(?<toVerse>[0-9]{1,3}))?)?)\[/bible]";

	Regex r = new Regex(pat, RegexOptions.IgnoreCase);

	MatchCollection m = r.Matches(textVal);
	foreach (Match match in m)
		string verseVal = "";
		string errorText = "";
		if (!String.IsNullOrEmpty(match.Groups["version"].Value))
			bibleVersion = match.Groups["version"].Value;
		string thisBook = match.Groups["book"].Value;
		int fromVerse = 0;
		int toVerse;
		if (!String.IsNullOrEmpty(match.Groups["verse"].Value))
			fromVerse = Convert.ToInt32(match.Groups["verse"].Value);
		toVerse = fromVerse;
		if (!String.IsNullOrEmpty(match.Groups["toVerse"].Value))
			toVerse = Convert.ToInt32(match.Groups["toVerse"].Value);

		using (var bdc = new bibleDataContext())
			var searchVersion = bibleParts.theVersion(bdc, bibleVersion).SingleOrDefault();
			if (searchVersion != null)
				var searchBook = bibleParts.theBook(bdc, searchVersion.language, thisBook).SingleOrDefault();
				if (searchBook != null)
					var searchVerses = bibleParts.theVerses(bdc, searchVersion.version, searchBook.bookID, Convert.ToInt32(match.Groups["chapter"].Value));
						if (fromVerse != 0)
							searchVerses = from v in searchVerses
										   where v.verseNum >= fromVerse && v.verseNum <= toVerse
										   select v;
							string realToVerse = "";
							verseVal += String.Format("{1}{0}{2}", match.Groups["entire"].Value.Replace(match.Groups["book"].Value.Trim(),, "<span class=\"bibleHead\">", "</span>");
							verseVal += "<span class=\"bibleContent\">";
							foreach (var theVerse in searchVerses)
								string verseFormat = "{2}{1}{3}{0} ";
								if (String.IsNullOrEmpty(match.Groups["toVerse"].Value) && !String.IsNullOrEmpty(match.Groups["verse"].Value))
									verseFormat = "{0} ";

								verseVal += String.Format(verseFormat, theVerse.thisVerse, theVerse.verseNum, verseNumBegin, verseNumEnd);
								realToVerse = theVerse.verseNum.ToString();
							verseVal += String.Format("{1}{0}{2}</span>", searchVersion.copyright, footerBegin, footerEnd);
							verseVal = verseVal.Replace(String.Format("-{0}", toVerse), String.Format("-{0}", realToVerse));
							verseVal = verseVal.Replace("-</span>", "</span>");
					errorText = "The book \"{0}\" does not exist.  Please check the spelling and try again.";
					errorValue = match.Groups["book"].Value;
				errorText = "The version \"{0}\" is not installed on this server";
				errorValue = match.Groups["version"].Value;
			if (String.IsNullOrEmpty(errorText))
				textVal = textVal.Replace(match.Groups[0].Value, verseVal);
				textVal = textVal.Replace(match.Groups[0].Value,String.Format(errorText,errorValue.Trim()));
	return textVal;

Currently active at

Web design

Firebug primer by Hugo

For those that are not aware Firebug is a add-on for Firefox, and is essentially a development debugging tool, that allows you to inspect various aspects of a web page.

It has become – for those that have used it for a while – one of those indispensable tools that make day to day coding life that much more productive.

This post is by way of introducing those unfamiliar with it to it’s most basic functionality, I do not attempt to explore any of the deeper functions but concentrate on the HTML / CSS tools available.

The image below shows the Firebug console on initial activation.

The HTML tab is selected and this shows an initial view of the pages markup in the panel to the left hand side at the bottom. To the right is a view of the CSS rules that apply to this page and to this element specifically in the initial view and is selected using the tab above marked ‘CSS’ (more about the other views later).

The image above shows the options selectable for the HTML markup view.
The important options are the three bottom ones:

  • ‘Highlight changes’ this will place a background to the element being viewed or that is receiving focus and helps greatly when the markup dynamically changes
  • ‘Expand changes’ this feature will automatically reveal collapsed branches in the markup (note the plus sign against the element nodes in the makup view which are clickable to inspect nested detail) when the page refreshes or one inspects an element in the main viewport (see later explanation on ‘inspecting’)
  • ‘Scroll Changes into view’ very useful as this moves the html view to the element in question rather than you have to find it in a large and complicated page

Next is where Firebug starts to get interesting!

The image below shows a view when one uses the ‘inspect’ button whilst in html view

Note the blue bounding border around the text in the viewport; when you click the ‘Inspect’ button you can then move your pointer over any portion of the rendered viewport display, as you highlight elements they will be demarcated by the blue border, as this happens you will notice two things occurring firstly the html markup view will be scrolling to the element that you have hovered over and the CSS view in the right hand pane will jump to the specific CSS rulesets that style this element.

When an element is highlighted you may click on the element and this will ‘fix’ this element in the two view panes in Firebug allowing you to further inspect aspects without loosing the focus on that element.

The image above shows a further method to inspecting elements and one that provides a further level of detail that is extremely useful. By clicking on any element in the left hand Firebug pane showing the page markup you will be able to highlight the elements padding and margins, this can be seen as the yellow highlight which represents the margins of the element and the purple highlight which represents the elements padding applied.

Moving on to the CSS aspect of Firebug demonstrates some invaluable tools and information that make dealing with CSS cascade and inheritance much easier and is perhaps is a feature above all others that would justify installing and learning to work with Firebug.

Looking at the right hand pane showing CSS rulesets shows us some very important information firstly it show us all the rulesets and properties that have been applied to the element highlighted in the left hand pane but much more than that it shows us specifically the specificity order of those rulesets in other words it shows us those rules that carry the heaviest most important weight first it then shows rulesets of a lesser value but that have been applied to the element, and thirdly it shows us properties that have been inherited by the element from parents or ancestors, note the “Inherited from div.content” heading, this is telling us that there was a font-size applied to any div with a class ‘.content’ and that as .submit and/or a paragraph was a child element of that div.content it had inherited that font-size; which brings us to the final feature of this CSS view, note the strikethrough on that inherited ruleset font-size, Firebug is telling us that in actual fact although this property was inherited in reality it was overwritten bu a more specific font-size described on the child element.

This set of features and information make debugging CSS problems extremely fast and far easier than having to wade through the stylesheet trying to understand where there might be an inheritance or specificity issue. On a final note please observe the line numbers to the right of the rulesets these correspond to the actual line numbers in your stylesheet which further speeds up locating specific rulesets; In the examples I have used grabbed from the forum It went unnoticed until too late that cetain styles/stylesheets appear to be ‘packed’ or ‘minified’ and thus all rulesets are in fact collapsed to a single line to preserve space and reduce file size, hence we mainly see ‘(line 1)’ normally this would show as mentioned earlier, an example of actual line numbers can be seen if you look further down at the third rulest that has a file name html.css and a line number of ‘(line 65)’

A further aspect of the right hand view can be seen in the image below where the ‘layout’ button has been selected. This speaks for itself but briefly it shows the aspects of the elements box model.

Lastly in either viewing pane one can edit in real time either the markup or, as shown in the image, the CSS rulesets, you can add new properties, delete existing ones or simply modify existing ones.


Firebug is a very powerful tool and one that simply increases ones productivity; I can’t stress enough though that I have only scrapped at the surface of what it can show and do and concentrated on the basic HTML/CSS features, if you’re working with client side scripting Firebug becomes equally indispensable in allowing you to observe in real time dynamic changes to the page.

There are other aspects that I leave to the reader to discover but once you do you’ll realise why you can’t really do without this tool 🙂


Why I don’t do xmas

  1. It involves lying.
    • Do you tell your children “if you’re good Santa will bring you presents”? That’s a lie.
    • Do you tell your children that Santa exists? That’s a lie.
    • Do you tell your children that Santa actually flies in a sleigh and delivers gifts? That’s a lie.
    • It encourages children to lie. “Yes, I was good.”
  2. Xmas and Jesus’ birth are so closely tied that disbelief in one causes disbelief in both.
    • “Well, we lied to you about Santa but Jesus is real. Honest!”
    • When children are told “these gifts came from Santa but Jesus is the real reason for the season”. They can touch the gifts from Santa but what can they see from Jesus? The fraud wins. Forgiveness of sins and escape from damnation mean very little to a child.
  3. It encourages greed
    • What’s the first thing you think about when considering xmas? Some reading may say “Jesus’ birth” but most will say “presents”.
    • Ask a child for their reply.
  4. It’s a sad time for many, many people
    • Folks that have lost a loved one during this time feel miserable.
    • People that have no one during this time of year feel miserable.
    • People that can’t afford the gifts they are forced to give feel miserable a little bit later when the bills come in.
  5. Jesus’ birth wasn’t on December 25th.
  6. I’m not a catholic and don’t follow their traditions including valentine’s day, halloween and xmas, et al.

Look, friends, I don’t want you asking my son if he got anything from Santa. I don’t want you telling my son that if he’s good Santa will bring him presents. I’m not going to lie to him and I don’t want him lied to by others.

Web design

Join Project Honeypot

Stop Spam Harvesters, Join Project Honey Pot


A fake iPod

For those of you that still insist on using ebay I’d suggest caution when purchasing an “iPod” from ebay.

Counterfeit Official iPod
fake iPod real iPod
There is a little apple logo and the word “iPod” at the bottom of the screen I don’t see that logo on the real iPod
fake iPod real iPod
Memory and processor chip at top (behind screen) Memory and processor at bottom near connector
fake iPod real iPod
Fake iPod battery is about ¼ the size of the battery in the official iPod Official iPod battery takes up most of the space in the case.
A screw held the plate on the back of the counterfeit iPod (sorry, I forgot to take pics) I don’t think the real iPod has any external screws
Non-functional counterfeit iPod has an hourglass icon Non-functional real iPod has either a warning triangle icon with an exclamation point in it or a sad faced iPod logo
Web design

Let me check my calendar

OK, this is 2008. I know there are tons of hack web designers out there that bought a copy of dreamweaver but please give me a break. Hey, I’m not against hacks, I mean someone’s got to do pages for $10 or else the bait shop won’t ever get a web site. I just want to help you not look completely incompetent.

I have my speakers on because I sometimes like to listen to music when I’m working. A lot of other people do, too. When I go to a web page I. DO NOT. WANT. The accursed thing to scream at me or play me a flourish or orchestral hit. Sometimes I have my speakers on at night when others in the house are sleeping and that’s not only unprofessional, it’s just not courteous.

So please, since for some reason you refuse to do away with your stupid, worthless, out of date since 1997 splash pages at least get rid of the idiotic automatic sound. That is, of course, unless you enjoy being a laughing stock and enjoy your marvelous hit counter to remain at one visit (from your mother, she’s the only one that would bother to look).

I was going to post links to offending pages but the last 5 I ran across have been from the same “web design” company. 🙄

Humor Why I am the way I am

Why I am the way I am – IV

Grade: Kindergarten

Age: 4

It seemed like a regular Friday. We had alphabet, milk break and recess just like every regular day. After recess we’d normally just sit and draw or play and wait to get ready for the bus. Miss McNanny announced after recess that we should each pick a partner for “something special”.

That was an easy one, Steve Mohr. He was the kid that came up to me on the first day of kindergarten and asked “Do you want to be best friends?” and I said, “Yeah.” It was then official, we WERE best friends so he was my pick and I was his. Simple, right? Nope. It turned out that Wanda McKnight’s (or maybe it was Wendy they were identical twins and I just called them both McKnight) twin was sick that day so she didn’t have a partner so she got put with us. Steve and I shrugged and welcomed her aboard for the “something special”.

The bus was ready to take us home so the “something special” was apparently “something secret” that we’d have to wait until Monday to find out about. I think I was learning so when Steve asked me all excited-like “what do you think this is all about” I had a genuine fear and my stomach got a hard knot in it and I just stared out the bus window wondering.

The weekend was mine and I did not even think about school. Saturday morning cartoons with super sugary cereal then exploring the woods or a construction site. The neighborhood kids were always around and even though they liked to tease me they’d always teach me something or make me laugh, too.

Monday morning rolls around and I think about feigning ill health in hopes that the returning twin would get put in my place but I couldn’t do that to my best friend. He’s surely counting on me. To the bus stop. *sigh*

The big announcement: We are going to put on a circus. The kids all cheered except for me and the 7 year old. This is going to be bad. Very bad.

Just before recess everyone gets their circus assignments. Two kids were told they were elephants and they went out to recess. Two were tigers and they got released to recess. The two clowns got sent to recess along with the lions and monkeys, etcetera, etcetera.

Steve, McKnight and I are last and we get our assignments. “You are going to be the seals.” says Miss McNanny. Great. I begin to walk out to recess sans all forms of enthusiasm.

“Hold on,” she says. “You’ve got to practice.”

“But I want to go play with everyone else,” says me and even Steve started to protest. No one else had to practice. Just me and those affiliated with me. They were jinxed by association, I suppose.

“Don’t you want to do something special? More special than recess?”

“Ummm. No?” and I look to Steve for backup. He shrugs and looks down.

Miss McNanny had us throw a ball back and forth and after she watches us do it she must have though I wasn’t a good at playing catch because she tells me “You’re going to be the SEAL TRAINER! 😕

Now I was only 4 but I wasn’t stupid. I knew there were elephant trainers and lion trainers but I had never in my life heard of a seal trainer. What in the world was this lady smoking?!? We were just a few years out of the 1960s but come on!

For the next TWO WEEKS Steve, McKnight and I didn’t have recess and I’m going to be honest I was angry like the neighbors cat that I tried to teach to swim by dunking it in their pool. Steve and McKnight had to perch themselves on milk crates and I had to tell them to throw the ball to each other. I did NOT have to be there. I could have been AT RECESS!!!!! They can throw the ball without me telling them. I was distracted by the gleeful screams and laughter which tauntingly echoed from the cement recess area from just outside the realm of the seal trainer. 🙁

I went through the “practice” day without recess in and day without recess out and on the last day Miss McNanny invited the kids in grade 1-4 to watch our final practice. It was a dress rehearsal so all the other kids got to walk in a circle with animal or clown masks on and the older kids all clapped. 😕 I was forced to wear a red paper hat and a coat that smelled like moth balls and bad breath and got a big bushy mustache taped under my nose. I looked just like the guy that used to sleep on the bus stop benches down town. He had a mustache and a stinky coat, too.

Then it was our turn and I was not about to perform for anyone so I refused. Miss McNanny pushed the ball to me and I pushed it back to her and crossed my arms. She kicked the ball and it swept my feet out from under me and I fell and all the older kids laughed at me. I tore my hat and mustache off and threw down the malodorous coat and went to the rest room and hid until the bus came.

On the next day we found out that Miss McNanny invited our parents to watch our Cirque Du Imbéciles. I was mortified. I already got laughed at once and I decided that was never going to happen again.

The other kids walked around the parents and received their applause and it was our turn again. Steve and McKnight had stockings over their faces and looked more like bank robbers than seals. I had on my torn up hat, mustache and smelly coat and I totally choked in front of the parents, I couldn’t even talk. I couldn’t even move. My mom was there and I froze. Miss McNanny had a little music maker that was playing circus music and I pretended to be interested in it so I wouldn’t have to do my act. She tried to shove me out. There was no way I was ever going to perform in front of people again in my entire life. I hid my face against the wall and only peeked out once when Miss McNanny took my place and told Steve and McKnight to throw the ball to each other.

The next school day was almost back to normal. Recess was again mine. I think Steve was a bit upset with me but we were still best friends. My mom didn’t disown me so it wasn’t the worst thing that could happen but I never could speak in front of people after that. I can still see those fat, dirty faces laughing at me when I get in front of people and I still freeze up.

Lesson learned: The clothes (and mustache) make the man into a nervous wreck.