JavaScript & ASP.NET: Executing on an Event onclick
Posted by Chris | Filed under ASP.NET, JavaScript
I’ve been doing a lot of front-end debugging with ASP.NET and JavaScript lately, and one thing has become very apparent: there’s way too many ways to specify that something happens when you click on an link or other element.
First, you could specify what happens when an element is clicked using the classic but naive onclick [...]
Tags: javascript onclick asp.net
.NET, Philosophically
Posted by Chris | Filed under .NET
Question: Who deserves a kick in the nuts more—the Microsoft BCL developer who brilliantly decided to name his Uri method TryCreate, or the “Sr. Engineer” on your team who neglected to ever use Intellisense and instead decided to drop this steaming gem of useless crap into your already-herniating codebase? (Snippet from a friend’s workplace.)
public static [...]
Tags: humor
Config files for DLLs
Posted by Chris | Filed under .NET, C#
Use .config files for your class library DLLs just like you would with an ASP.NET’s web.config.
Tags: web.config config file settings
Short GUID
Posted by Chris | Filed under .NET, C#
Create a short GUID in .NET.
Expiring Cache in C#
Posted by Chris | Filed under .NET, C#
Ever need a simple cache that automatically expires items, removing them after a given time has elapsed? Well now you’ve got it: ExpiringValueCache and ExpiringObjectCache. ExpiringValueCache is used to store value types. ExpiringObjectCache is used to store reference types.
A background thread continuously runs, checking for expired items in a generic Dictionary. The size of the [...]
Get the XPath to an XML Element
Posted by Chris | Filed under .NET, XML
Problem
Given an XElement, what is its XPath?
Preface
Many XPaths can be used that will select an XML element. To select one and only one element, indexes need to be used. For example, given the following XML data:
<people>
<person>
<name>
<first>Chris</first>
</name>
</person>
<person>
…
</people>
The XPath “/people/person” will select all the “person” elements that are children to “people.” To refer to the first “person” [...]
Syntactic Sugar for C#
Posted by Chris | Filed under .NET, C#
I have a small list of demands for C# that comes only out of love. Hell, they even make sense. Can we get these supported in C# 4.0, or what? Unlikely, but ideally. If you saw my post about Guid.TryParse(), you’d know that these things can take ones. One can hope though!
Variable Declaration in If [...]
Hexadecimal value 0x is an invalid character
Posted by Chris | Filed under .NET, XML
Ever get a XmlException that says:
“Hexadecimal value 0x[whatever] is an invalid character”
…when trying to load a XML document using one of the .NET XML API objects like XmlReader, XmlDocument, or XDocument? Was “0x” by chance one of these characters?
0×00
0×01
0×02
0×03
0×04
0×05
0×06
0×07
0×08
0×0B
0×0C
0×0E
0×0F
0×10
0×11
0×12
0×13
0×14
0×15
0×1A
0×1B
0×1C
0×1D
0×1E
0×1F
0×16
0×17
0×18
0×19
0×7F
The problem that causes these “invalid character” XmlExceptions is that the data being read or loaded contains [...]
Add a CSS Class in ASP.NET
Posted by Chris | Filed under ASP.NET, CSS
Adding or removing a CSS class to an element in jQuery is easy enough:
$("#elementId").addClass("className");
$("#elementId").removeClass("className");
But how can this be done in ASP.NET? Shouldn’t it be as easy? Should? Yes. Is? Almost. For the quick solution and code, jump to the end of this post. (That’s what this is really here for anyway—to host the code for [...]
Simplify jQuery with ASP.NET Web Services and JSON
Posted by Chris | Filed under ASP.NET, Ajax, jQuery
Introduction
In my last post, I gave a quick introduction to using jQuery for JSON communication with ASP.NET web and WCF services. It’s not very complicated, but it’s distinct enough from consuming XML or other services to warrant a little explaining.
In this post, I’m going to suggest you save yourself of writing out or copying/pasting that [...]
Tags: Ajax, ASP.NET, ASP.NET AJAX, JavaScript, jQuery, JSON, JSON dates, parse JSON dates, web services