HTML5 Placeholder Attribute

When creating web forms it is often nice to throw in a hint as to what should be entered into the field. This is a nice nuance that adds a nice level of interaction to your site. Previously you would have had to use JavaScript and click events to remove the hinting text from the form field and change the style once the user clicked on it.

042912_2146_HTML5Placeh1

That was a lot of work!! Finally in HTML5 you can placeholder text to your form fields with a simple HTML attribute:

<input type=”text” placeholder=”Last Name” />

Check out this Demo to see it in action: http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_input_placeholder

*BAD NEWS: It does not work in IE9 and below. It is currently supported in IE10 (only released as preview when writing this). It will work in most other browsers. Unfortunately for the time being, not working in IE9 might be a deal killer (at least for a while).

An additional key feature is that you can also use placeholder attribute for inputs of type “password”. Previously if you tried to do this with JavaScript you would need to switch out two different input elements so your placeholder text does not show “*****”.

No Comments

CSS & !important Declarations

The CSS declaration for “!important” has been around for a long time – since the original CSS specification. However, not many people understand exactly what it should be used for, and more importantly what it SHOULD NOT be used for.

First of all, what exactly does this declaration do? If you are mildly familiar with CSS techniques, then you understand the “Cascading” part of the CSS name. The ability to override a style with specificity (the concept of being more specific when writing a style), and have it cascade to multiple elements below is a very powerful tool. The important declaration overrides the cascade and ignores styles that are more specific. It ensures that your style is “most important”. The drawback here is that if you use this then you prevent people from using the Cascading Style Sheets the way they were meant to be used.

A personal pet peeve of mine is when people use it simply because they are too lazy to figure out how to properly override a style with specificity. That being said, the declaration can be handy in some scenarios. The declaration should generally only be used for two basic scenarios in my opinion:

1. Temporarily – You can make lots great use of the declaration for temporary purposes. By this I mean when you are working inside your developer toolbar and want to test a style out, or perhaps you are working on a style and just want it to take effect for testing purposes.
2. Third Party Components – Sometimes when using a Third Party component that injects its own CSS styles, there is simply no way to override a particular style in question. You have maxed out your specificity, your only option left is to use the important declaration.

This article here is a fantastic summary about some specific scenarios for using Important such as, and re-iterates some of the points I made as well:
- To Aid or test Accessibility
- Special Blog Posts
- Print Stylesheets (thought this was an interesting use of the declaration)
http://coding.smashingmagazine.com/2010/11/02/the-important-css-declaration-how-and-when-to-use-it/

No Comments

Visual Studio Weird Characters with ALT+SHIFT

Every once and awhile in Visual Studio I am typing along and somehow end up with some type of alternate keyboard turned out. My only way to reset it was to restart Visual Studio. I finally got tired of this, and decided it must be a keyboard shortcut I am hitting by accident. After a bit of searching, I found that ALT + SHIFT seems to change the keyboard culture. I can toggle back and forth with this combination. Seems weird that a such a simple combination would do this, thus why I encounter so often I guess.

, , , , ,

No Comments

Team Foundation Service (TFS) Preview

You read the title correct, I did say SERVICE and not SERVER. This new Team Foundation in the Cloud offers all the TFS Server functionality in a fully managed environment. Currently this is in preview mode, and is 100% free to sign up and get yourself a nifty subdomain:

yourdomain.tfspreview.com

It was incredibly easy to setup. You basically walk through a couple of web pages and link it in through your @live account. In a matter of minutes you are up and running with TFS and a project. You do need VS2010 with SP1 to get use of the Visual Studio Integration. Also, it is working out of the box with the VS11 Developer Preview, and apparently has some additional features you can take advantage of, though I’m not aware of what they are yet – Please let me know if you find them.

This version includes web-access to all files, including comparison mode (just like TFS). At first glance everything seems present that I normally use from day-to-day, including branching, merging, etc. You can even setup your own build server locally that will integrate with TFS in the cloud, and queue builds, etc, exactly as you would with a local TFS box – nicely done Microsoft!

Sign-up and Introduction URL: http://www.tfspreview.com

You will need an invitation code in order to sign-up (since it is in preview). I was lucky enough to find a fellow blogger who could part with one.

Although this product is currently free to use right now, upon final launch of it each account will be given 30 days to either begin paying for the account or retrieve all your code – no word on pricing yet. Microsoft has said that you can use this service in preview mode for Production code.

Looking forward to seeing the pricing on this service and where it goes in the future.

, , ,

No Comments

HTML 5 DOCTYPE Caution

So your using HTML 5 now. You just put in your DOCTYPE as:

<!—- Using HTML 5 finally woo hoo! –>
<!DOCTYPE html>

You open up your HTML 5 page in IE9 to discover that it forces you automatically into IE9 Compatibility view! WHAT? Why would I want to be in compatibility mode when I’m building a new website?

The key is that in the specifications you cannot have anything render before the DOCTYPE. So simply remove any comments you may have put in above the DOCTYPE and you’ll notice everything is now working as expected! Makes sense….but very disappointing if you lost some time to something so inconspicuous.

, ,

No Comments

ASP.NET 4.0 Url Routing and Modules

Was working on an ASP.NET website this past week that got flipped over to ASP.NET 4.0 without the team really being aware of the change. A very apparent bug popped up, where a http module we had running on every request (for security purposes), had the current identity user coming back as NULL only on specific URL’s. With some testing and debugging, we found those URL’s to be directories when the module would fail. After finding that I immediately thought about how the .NET 4.0 URL Routing feature might be affected by this?

It turns out that modules are not loaded on every request. In this instance the Membership module needed to be loaded. Essentially the solution is to manually add the required module in our web.config and removing the entry (with a remove statement) from the inherited entries. Be sure to set the precondition=””.

I know I have explained this all very poorly, but you get the gist. Check out this article on routing in IIS7 for all the details!

http://www.heartysoft.com/aspnet-routing-iis7-remember-modules

, ,

No Comments

DataTable .Select and .RowFilter Escaping with Apostrophe’s

One of the great things about the DataTable or DataView is its ease of ability to Sort and Filter data. Often I utilize the .Select method of DataTable. This involves writing a short where clause string to provide to the method. The contents of this select filter in my scenario actually contained an apostrophe in the string. Thus I had something like this:

table.Select(“column1 = ‘Apostrophe’s’”);

You will note here, the single apostrophe used inside the value. Unfortunately, this is not automatically handled by the select logic, rather we need to properly escape our values. Interestingly enough, I found this article:

http://aspnetresources.com/blog/apostrophe_in_rowfilter

This article talks about Microsoft’s suggested usage for escaping this instance with a back slash:

table.Select(“column1 = ‘Apostrophe\’s’”);

But, that fails horribly. You actually escape the character in this usage, with a second apostrophe, much like you would in a SQL statement:

table.Select(“column1 = ‘Apostrophe’’s’”);

This means that you simply have to use a global replace on the contents of your value if its dynamic (i.e. stringVal.Replace(“”, “’’”); ).

, , , , , ,

1 Comment

MSBuild Can’t Find Secondary References

That is right, you read the title correctly. MSBuild in versions 2005, 2008 and 2010 of VS does not find and include secondary references. This means that if you have a project Class Library that contains “Content” items that are supposed to copy to the bin, if you reference that assembly, MSBuild publish will not output those files into your website bin (don’t get confused with a Visual Studio Publish – that works fine still!).

What does this mean?

When grabbing output from Build Server under _PublishedWebsites (from the drop location, Releases), don’t expect to see this content in the bin. This makes auto-deployment scenario’s increasingly harder.

Microsoft’s recommended work around is to include that content item that is a secondary reference, directly in your Web application project…..LAME!

Information all found at these articles:

http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/b42c1097-463c-4f20-a171-f9b06d90617a/

http://sstjean.blogspot.com/2006/11/msbuild-cant-find-secondary-references.html

, , , , ,

No Comments

External Project Resource (RESX) Consumption

Using resource files can sometimes be troublesome when you need a particular resource in both a Web application mark-up or code-behind and inside a business tier or data model. When you push the Resx file further back into you’re project, you’ll likely need to create it as an embedded resource for easy entry. From there you can quite simply access that resource in any code (as long as you’re referencing the project containing the resx file), as follows:

Namespace.ResourceFileName.ResourceManager.GetString(”ResxItemName“);

You can of course add a “using” statement and remove the Namespace from it. You can also use this in an .aspx or .ascx markup file:

<%= Namespace.ResourceFileName.ResourceManager.GetString(”ResxItemName“); %>

When using in markup, you can also add a Namespace Import and reference without the Namespace prefix:

<%@ Import Namespace=”Namespace” %>

<%= ResourceFileName.ResourceManager.GetString(”ResxItemName“); %>

In some cases, it may make sense to create yourself an entire Class Library Project purely devoted to storing all your Resource files. Then you can simply use that reference anywhere you need it without worrying about circular dependencies.

, , ,

No Comments

Dynamic WCF Client Endpoint

WCF is fantastic for easy communication between applications. WCF is normally implemented using binding configurations embedded in each application. You usually have configuration for your server, and also your endpoint for your client. I found myself in a situation in which I had no readily available configuration file to use, as well, the endpoint address was dynamic itself based on the application that is consuming this library. Thus, I began searching on how to programmatically setup your client endpoint. Turns out, it is not that hard. Check it out:

// dynamically configure based on passed service url
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress(“http://SPS02:4762/StatService.svc”);
var channelFactory = new ChannelFactory(binding, endpoint);

// create and make channel call
IStatService service = channelFactory.CreateChannel();
StatResults results =  service.PostStats(“hello world”);

In my example, I have created a custom statistics posting service. So, IStatService and StatResults is just the service contract created for must WCF service (these would change with your application). Notice the string passed in indicating the location of the service. This obviously creates a BasicHttpBinding configuration only, but you should be able to alter any of your standard WCF Configuration settings programmatically here too (make sure they match the service though J). With this above implementation I have NO config file (and the endpoint address is passed to this code – not hardcoded as shown above).

, , , ,

No Comments