CurtisTimson

Curtis Timson

ASP.NET Developer

Understanding jQuery data() storage

14 May

14 May 2013

It is a common misunderstanding that .data("key") is simply a shortcut for .attr("data-key").

.data() does read HTML5 data attributes, but this is only the first time it is called, as per the [documentation][1]:

The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally i...

console.log() vs alert() when debugging

28 Mar

28 March 2013

Using console.log() is a great way of getting quick results about what variables are holding what values at which point, and which areas of code are being called, without having to debug.

Before javascript debugging became so accessible, one of the only ways of checking the values of your variables would be to call alert(). However, this wasn’t ideal as it would stop the script from running...

Reading URL hashtag value

27 Jan

27 January 2013

URL hashtags were primarily used in order to position the page scroll on load to a particular element.

With javascript we can access what the value of the hashtag is on page load.

if (window.location.hash){
      var hash = window.location.hash.substring(1);
      alert(“hashtag value is ‘“ + hash + “‘“);
}

This snippet first checks that the URL contains a hashtag, and ...

Check javascript function exists before calling it

23 Nov

23 November 2012

On large applications, there may be some instances where you need to make a call to a function which belongs in a different javascript file.

There might also be a case where this javascript file isn’t always included on every page, and should only be called if it is included.

If we are to call this function, and it hasn’t been included, a javascript error will be returned.

Therefore we ...

Creating a new rule for a CSS class in jQuery

7 Oct

7 October 2012

In jQuery, to add a new style to all elements which have a particular CSS class, we can simply call a function like the following:

<div class="foobar">Lorem Ipsum</div>
<div class="foobar">Dolor sit amet</div>

function SetFooBarRed(){
    $(".foobar").css("background-color", "red");
}

This will add the style background-color:red to all elements with the class `foo...

How to prevent self-closing elements in XSLT

4 Oct

4 October 2012

If you are to put an element into XSLT without any child elements, the element will automatically close itself. Therefore, if you have the following markup:

<div class="clear"></div>

XSLT will automatically render this as:

<div class="clear" />

This is fine for most elements, however some elements such as <div> will behave differently if they are self-closed.

A good way of...

Using jQuery callback functions

5 Aug

5 August 2012

I've heard questions in the past regarding how to run a script after a jQuery animation or event has been completed.

The majority of these believe that you need to delay the script for a few seconds, allowing the animation to complete before the 2nd function is called. For example:

$foo.load("MyWebPage.htm");
$foo.delay(1000).css("color", "red");

Here, the jQuery object $foo is...

Strongly typed Stored Procedure names in C#

18 Jul

18 July 2012

Calling SQL Stored Procedures in ASP.NET as simple text strings can cause problems such as:

  • Typo in Stored Procedure name. This isn't a huge issue, but it can be costly if you later need to rebuild the application because of a simple typo!
  • Finding all references to a Stored Procedure. As the stored procedure is stored as a string, the only way you can find all occurrences of the stored p...

Welcome to my new site!

20 Apr

20 April 2012

Welcome to my new site!

The majority of my experience is using ASP.NET Web Forms & VB.NET, so I've decided to challenge myself by building this site in ASP.NET MVC3 Razor, LINQ & C#. So far so good!

I plan to use this site as a place to test new skills which I wouldn't necessarily get to put into practice straight away on live working projects.

Watch this space!

Hello!

Welcome to my blog site! I'm an ASP.NET Web Developer with 6 years experience in the industry currently working for a large retail company within the eCommerce sector.

Instagram

Can you help me?

If you know the answer to my StackOverflow question, please feel free to help me out!

Jump back to top