5.20.2008
Reusable Themes with CompiledThemeBuildProvider
Check it out on CodePlex!
Labels: ASP.NET, asp.net themes, buildprovider, compiled themes, reusable skins, reusable themes, skins, themes
4.18.2008
WorkingOn for FogBugz v1.3 Released
- Application should no longer crash when there is no network connection available, or if the network connection drops while the application is running
- If the application is unable to update, a message will be displayed and the automatic refreshes will be disabled. The user must manually refresh (using the Refresh menu item) or log in again to start the automatic refreshes again.
- The application should no longer attempt to set titles longer than 64 characters
- The login form will automatically parse the protocol (http or https), server/domain and application path from the Server field
- FogBugz installations in virtual directories and on SSL ports are now supported
- A list of cases that have had time logged by the user in the last 14 days are now displayed in the Recent Cases submenu
- The popup balloon shown after work is stopped on case now includes the total number of minutes logged.
Labels: Fog Creek, FogBugz, FogBugz v6, project management, Time tracking, Working On, WorkingOn
3.09.2008
Validatable CheckBox control
I took a different approach - instead of trying to make a custom validator for the CheckBox, why not just modify the CheckBox control so that it can be validated by a RequiredFieldValidator?
On the server side, this is as simple as creating a class that inherits from System.Web.UI.WebControls.CheckBox and adding the ValidationPropertyAttribute, like so:
[ValidationProperty("Checked")]
public class ValidatableCheckBox : CheckBox
The client side is a little bit more involved, but still fairly simple.
ASP.NET's client side validation checks an element's value property. If it returns anything, it is considered validated. Since the "value" property of a checkbox element returns "on" or "off", it will always be considered validated. To deal with this, I've created a javascript class that effectively overrides the "value" property of the CheckBox control's client HTML element so that it returns an empty string instead of "off" when it is unchecked.
You can check it out here.
To associate that javascript class with our server side control, you need to implement the IScriptControl interface. (For more info, see Adding Client Capabilities to a Web Server Control by Using ASP.NET AJAX Extensions)
I've done this here.
That is all! You can see it in action here, or download the demo solution here.
Labels: checkbox, checkbox validation, checkbox validator, checkboxvalidator, validation
10.30.2007
WorkingOn for FogBugz
http://www.codeplex.com/fogbugzworkingon
Labels: Fog Creek, FogBugz, FogBugz v6, project management
5.16.2007
More RegEx; US and UK phone numbers and postal codes
US Zip Code parsing pattern:
^(?<Zip>\d{5})[\s-]*(?<Plus4>\d{4})?$
Captures the 5-digit zip code to the named group "Zip" and the optional USPS 4-digit "plus 4" code to the named group "Plus4"
US Zip Code validation pattern:
^\d{5}[\s-]*(?:\d{4})?$
UK Post Code parsing pattern:
^(?<OutCode>(?:[ABD-HJLNP-UW-Z]{1,2})(?:(?:\d{1,2})|(?:\d[ABD-HJLNP-UW-Z])))\s*(?<InCode>\d[ABD-HJLNP-UW-Z]{2})$
Captures the first section of the post code to the named group "OutCode" and the second section of the post code to the named group "InCode".
UK Post Code validation pattern:
^(?:[ABD-HJLNP-UW-Z]{1,2})(?:(?:\d{1,2})|(?:\d[ABD-HJLNP-UW-Z]))\s*\d[ABD-HJLNP-UW-Z]{2}$
Valid UK postal codes follow the below patterns:
- A9 9AA
- A99 9AA
- A9A 9AA
- AA9 9AA
- AA99 9AA
- AA9A 9AA
US Phone Number parsing pattern:
^[\s(]*(?<AreaCode>\d{3})[\s-)]*(?<TownExchange>\d{3})[\s-]*(?<Number>\d{4})$
Captures the area code to the named group "AreaCode", the next 3 numbers to the named group "TownExchange" and the final 4 numbers to the named group "Number".
US Phone Number validation pattern:
^[\s(]*\d{3}[\s-)]*\d{3}[\s-]*\d{4}$
UK Phone Number parsing pattern:
^[\s(]*(?<AreaCode>(?:(?<ac01x1>01\d1)|(?<ac011x>011\d)|(?<ac02x>02\d)|(?<ac01xxxa>01\d{3})|(?<ac01xxxb>01\d{3})|(?<ac01xxxx>01\d{4})))[\s\-)]*(?<TownExchange>(?(ac01x1)\d{3})(?(ac011x)\d{3})(?(ac02x)\d{4})(?(ac01xxxa)\d{3})(?(ac01xxxb)\d{5})(?(ac01xxxx)\d{4,5}))[\s\-]*(?<Number>(?(ac01x1)\d{4})(?(ac011x)\d{4})(?(ac02x)\d{4})(?(ac01xxxa)\d{3}))$
Captures the first set of digits to the named group "AreaCode", the second set of digits to the named group "TownExchange", and the final set of numbers, if it exists, to the named group "Number".
UK Phone Number validation pattern:
^[\s(]*(?:(?<ac01x1>01\d1)|(?<ac011x>011\d)|(?<ac02x>02\d)|(?<ac01xxxa>01\d{3})|(?<ac01xxxb>01\d{3})|(?<ac01xxxx>01\d{4}))[\s\-)]*(?(ac01x1)\d{3})(?(ac011x)\d{3})(?(ac02x)\d{4})(?(ac01xxxa)\d{3})(?(ac01xxxb)\d{5})(?(ac01xxxx)\d{4,5})[\s\-]*(?(ac01x1)\d{4})(?(ac011x)\d{4})(?(ac02x)\d{4})(?(ac01xxxa)\d{3})$
These patterns match the following UK phone number patterns:
(01x1) xxx xxxx (matched by ac01x1)
(011x) xxx xxxx (matched by ac011x)
(02x) xxxx xxxx (matched by ac02x)
(01xxx) xxx xxx (matched by ac01xxxa)
(01xxx) xxxxx (matched by ac01xxxb)
(01xxxx) xxxxx (matched by ac01xxxx)
(01xxxx) xxxx (matched by ac01xxxx)
Source: http://en.wikipedia.org/wiki/UK_telephone_numbering_plan
Labels: phone number, post code, regex, regex pattern, uk, zip code
5.09.2007
RegEx Pattern: No Whitespace in String Literal
The quick "red fox" jumped over "the lazy" brown dog.
He needed to match the whitespace between each of the words, except the whitespace between "red" and "fox", and "the" and "lazy". Splitting based on the matches would return:
[0] => The
[1] => quick
[2] => "red fox"
[3] => jumped
[4] => over
[5] => "the lazy"
[6] => brown
[7] => dog.
The beast of a pattern I created uses a combination of forward and backward positive and negative assertions. So, without any further ado:
\s(?![^"]*\")|\s(?<!\"[^"]*)|\s(?=(?:[^"]*\"[^"]*\"[^"]*)+[^"]*$)|
\s(?<=(?:^[^"]*"[^"]*\"[^"]*)+[^"]*)
Note - you'll need to remove the line break from the middle of the pattern; I had to put one in for formatting purposes.
Labels: literal, pattern, regex, regex pattern, regular expression, string, whitespace
2.07.2007
ASP.NET side basically done
It was kind of tricky getting it to render the HTML without being on a real page - I forgot/didn't realize/should've known/etc that HtmlTextWriter needs have Flush() called before it actually writes anything to the stream. I'm guessing that method is normally automatically called by the Page object. It took me a bit of playing around to figure that one out.
The really nice part is that the overall amount of work that was required to get to this point was considerably less than I thought it would be. Now I have to wire up everything on the client side, which I think will actually be quite a bit more effort, since I'm not nearly as familiar with AJAX.
Labels: AJAX, ASP.NET, asynchronous, C#, HtmlTextWriter, JavaScript, Sys.UI.Control
ASP.NET for JavaScript rendered controls, continued
I started playing around with it last night, and already have discovered that some of my assumptions will need to be changed.
First, I can't use IScriptControl. IScriptControl depends on having access to a ScriptManager. More specifically, THE ScriptManager that will be on the actual page. So while I could just add ScriptManagers into the controls I create, it would be pointless since it would actually be able to do anything. I will still be using one method from IScriptManager though - IEnumerable
Also, I'm 90% sure that creating my own control type is a bit unrealistic. Its completely possible - with the Visual Studio 2005 SDK, I can even create my own custom directive (like <%@ WebServiceControl ... %>), but it seems more realistic to just inherit from UserControl. The question here is whether TemplateControl.LoadControl(...) (TemplateControl is the abstract class Page and UserControl both inherit from, LoadControl allows you to get an instance of a Page or UserControl from a virtual path) will work from the WebService if I just instantiate a new object.
Labels: AJAX, ASP.NET, asynchronous, C#, DOM, GetScriptDescriptors, IScriptControl, JavaScript, LoadControl, Sys.UI.Control, Visual Studio 2005 SDK
2.06.2007
ASP.NET for JavaScript rendered controls
The end result I want is to have a way of creating controls whose entire lifetime on the page itself is initiated and controlled by client script, and then have the controls’ properties updated without actually recreating the controls themselves. However, because of how tedious it is to design web pages and controls entirely using the DOM in javascript, I thought it would be really cool if I could use ASP.NET to generate the actual controls for me, and then have them returned via a web service. I can use AJAX’s IScriptControl to automatically create bindings between whatever server side control or object I create and the client side javascript class.
Some things I was thinking about:
-Creating a new control type (like .wscx for WebServiceControlXmakesitsoundcool) and IHttpHandler made specifically with the intent of being rendered into an XML stream for use with a WebService
- Would be designed like ASCX controls, with HTML and a codebehind. Maybe just inherit from UserControl? Problem with that is that it won’t be contained in a Page class.
- Factory objects would take an additional generic Type parameter, TWebServiceControl, and which would allow this functionality to actually become part of the DAL
-Web service list methods would take a list of existing objects as parameters. List response would contain two parts: XML with HTML content (the WebServiceControl) for new objects (ie, objects that are missing from the list of existing objects), and regular data types (contained in serialized ObjectFactory objects) for updates to existing objects.
Labels: AJAX, ASP.NET, asynchronous, C#, DOM, IHttpHandler, IScriptControl, JavaScript
2.01.2007
...OfTheDay
I'm am hoping for ...OfTheDay to become one of those useless sites that people with nothing better to do will sit and gaze at for hours. The idea is that users will submit a finite number of categories of "things" to vote on each day. Within each Category, users will submit a finite number of nominees for things that fall in to each Category. So for example, if a user created the Category "Fish", another user might nominate "Trout", while another might nominate "Salmon". Other users would vote on which Nominee should be the "Fish of the Day". The category with the most cumulative votes will be the "Thing of the Day". See? Completely useless, but I think it could be fairly addictive, especially if I added in incentives to vote and have your categories or nominees win. For example, the more you participate, the more your votes are worth, or something similar.
I will be taking advantage of AJAX's asynchronous communication to keep all the objects on the page constantly updated. In order to cut down on bandwidth consumption, all the controls will be rendered using AJAX's client script, which will allow me to update only the individual controls that have actually changed, instead of wasting bandwidth updating everything, as would be necessary with traditional ASP.NET WebForms, even if AJAX UpdatePanels are involved.
I will also be using a C# library called "ObjectFactory", which I can't talk too much about because it was written by a colleague of mine, Portman Wills. Basically, a single ObjectFactory object represents a record from a table in the database. On his recommendation, I have modified his version considerably so that the factories themselves can be used as WebServices, and also work directly with the "WebServiceControls" I will be creating later on.
Labels: AJAX, ASP.NET, asynchronous, C#, JavaScript
Subscribe to Posts [Atom]