Tahir Hassan's Blog

My Technical Notes

Tuesday, 11 November 2014

Formatting a Decimal to display a Financial Value

If we have a decimal representing a price, for example, then we want to display the decimal to two decimal places. We used `ToString` method with the specifier `F` for that:

Padding an Integer with Leading Zeros

In C#, to pad an integer with up to four leading zeros, we use the `D4` specifier:

Another way, using `string.Format`:

Friday, 7 November 2014

NLog: Create a named Logger

In Nlog, it is possible to have a specially named logger which works independently of all the other loggers. Below is the `<nlog>` element that has a logger named `MyLogger`. Note that it is marked as `final`, therefore all the loggers below it will not process the log message.

Below is how to instantiate `MyLogger`:

NLog sample configuration in Web.config

Following is a `web.config` file with NLog configuration, with two targets, `debugger` which logs to the Output Window, and `logfile` which logs to the log file path specified:

Here is a sample test web page's code behind:

Wednesday, 5 November 2014

Styling JQuery Tooltip plugin

To style the JQuery Tooltip plugin, I define a JQuery plugin `tooltipX`:

Thereafter I apply it to an element:

Once the element is hovered over, then I have an opportunity to style it.

Wednesday, 15 October 2014

CSS clearfix AKA group aka whole class

If you wish to have a "container" css class which contains all of its children, then you are searching for the CSS clearfix hack.
If you had a left-floated div `l` and a right-floated div `r` in a container, but you wanted everything underneath it to not to go left or right of either `l` or `r`, then you want a special container css class which stops this. with the `whole` class not defined, it looks like so:
If we wanted the `what-follows` div to be underneath the floated divs, then we would define the `whole` class as follows: With this CSS class defined, the `whole` div will act like a "whole":

Thursday, 2 October 2014

Error message 401.2.: Unauthorized: Logon failed due to server configuration

If you are using Windows authentication within your `web.config`:

then you must also enable Windows Authentication within the project properties. Strangely enough there are two windows for this. The first one is when you right click the Project and go to `Properties` (or `Alt-Enter`):

The other one is the `Properties Window` which can be opened by clicking on `VIEW` → `Properties Window` or alternatively press `F4`. Here is how that looks:

Change `Windows Authentication` to `Enabled`.

This blog post was based on Saravanan's blog post.