Monday, 14 November 2011

Dimensions Of A Series Paper Sizes


There is a short table of the paper sizes of A series:

Size Height x Width (mm) Height x Width (in)
4A0 2378 x 1682 mm 93.6 x 66.2 in
2A0 1682 x 1189 mm 66.2 x 46.8 in
A0 1189 x 841 mm 46.8 x 33.1 in
A1 841 x 594 mm 33.1 x 23.4 in
A2 594 x 420 mm 23.4 x 16.5 in
A3 420 x 297 mm 16.5 x 11.7 in
A4 297 x 210 mm 11.7 x 8.3 in
A5 210 x 148 mm 8.3 x 5.8 in
A6 148 x 105 mm 5.8 x 4.1 in
A7 105 x 74 mm 4.1 x. 2.9 in
A8 74 x 52 mm 2.9 x 2.0 in
A9 52 x 37 mm 2.0 x 1.5 in
A10 37 x 26 mm 1.5 x 1.0 in

I found it there.

Tuesday, 27 September 2011

Where is the Ajax Control Toolkit Reference?


It is so easy to find.

Just go to the sample site (every google search points there), and:

Click on Getting Started tutorial.

Click on Tutorials.


And you will find the reference of each controls. And you will see the full reference on server and client side properties, events and methods.

It is easy to find, not?

Not every man should be a computer programmer


The question is only that: Why???


Code Snippet
  1. catch (Exception ex)
  2. {
  3.     if ((ex.GetType().ToString() == "System.Data.SqlClient.SqlException") && ex.Message.LastIndexOf("Timeout expired") >= 0)
  4.     {
  5.        /// Secret code
  6.     }
  7.     else
  8.         throw ex;
  9. }

Why the hell he doesn’t go and play football instead of programming?

Tuesday, 20 September 2011

Fed up with windows


The point is arrived. Enough. I am fed up with windows.


But I hope, it will comes back.

Monday, 7 February 2011

Generate RDLC dynamically with unique column headers

I use the great example from Gotreportviewer since about six month that uses Microsoft Reportviewer and my biggest problem is giving columns titles that different to field names.

There is my solution that has an additional property: List<string> Headers that contains column titles with the following restriction:

Number of headers must be equal to number of columns or TableRdlGenerator throws the following exception:
Error creating report: header and field columns must be set and have to be the same count of elements both of them!

The entire solution can be downloaded from my public folder on skydrive.

Sunday, 6 February 2011

jQuery based collapse extender web user control for

After I have been started to learn jquery I decided to replace my Ajax Control Toolkit controls for a jQuery-based solution.

My control for replace in that week is the CollapsiblePanelExtender. I need a solution that works on partial page postbacks and full page postbacks too and stores collapsed state during postbacks, and, of course I have to be able to change the collapse state on server side so I had to mix server and client side code for the solution.

Note: at the end of the post, I share the zipped full Visual Studio 2010 solution.

The extender needs the following informations:

    • Collapsed: The state if the target control collapsed or not.
    • TargetControlID: The ID of the panel that will be collapsed.
    • ToggleControlID: The ID of the control that we will click on when toggle or collapse.
    • ToggleTextID: The ID of the control that shows different texts on different states.
    • ToggleImageID: The ID of the control that show different images on different states.
    • ExpandedText: Text to show when the control is expanded.
    • CollapsedText: Text to show when the control is collapsed.
    • ExpandedImage: Image to show when the control is expanded.
    • CollapsedImage: Image to show ehen the control is collapsed.

The code behind of the web user control:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JQueryCollapse
    public partial class jQueryToggleExtender : System.Web.UI.UserControl
        #region properties
        /// <summary>
        /// Defines if the panel to collapse is collapsed or not.
        /// </summary>
        public bool Collapsed
                return hfCollapsed.Value == "1" ? true : false;
            set { hfCollapsed.Value = (value ? 1 : 0).ToString(); }

        protected string _TargetControlID;
        /// <summary>
        /// A conntrol to collapse and expand
        /// </summary>
        public string TargetControlID
            protected get
                return GetClientID(_TargetControlID);
                _TargetControlID = value;

        protected string _ToggleControlID;
        /// <summary>
        /// A control to toggle.
        /// </summary>
        public string ToggleControlID
            protected get
                return GetClientID(_ToggleControlID);
                _ToggleControlID = value;

        protected string _ToggleTextID;
        /// <summary>
        /// ID for toggle text control.
        /// </summary>
        public string ToggleTextID
            protected get
                return GetClientID(_ToggleTextID);
                _ToggleTextID = value;

        protected string _ToggleImageID;
        /// <summary>
        /// ID for toggle image control
        /// </summary>
        public string ToggleImageID
            protected get
                return GetClientID(_ToggleImageID);
                _ToggleImageID = value;

        /// <summary>
        /// Text to show when expanded
        /// </summary>
        public string ExpandedText { get; set; }
        /// <summary>
        /// Text to show when collapsed
        /// </summary>
        public string CollapsedText { get; set; }
        /// <summary>
        /// Image to show when expanded
        /// </summary>
        public string ExpandedImage { get; set; }
        /// <summary>
        /// Image to show when collapsed
        /// </summary>
        public string CollapsedImage { get; set; }

        /// <summary>
        /// Get a ClientID for a control by ID
        /// </summary>
        /// <param name="id">Id of the control</param>
        /// <returns></returns>
        protected string GetClientID(string id)
            Control c = ControlUtils.FindControlRecursive(this.Page, id);

            return null != c ? c.ClientID : null;

In the markup we need to include our javascript files. For getting this work on partial page and full page postbacks and any other cases we rendering script block in InlineScripts as shown in my previous post before. We store collapsed state in a simple hiddenfield because we can reach it’s value on server and client side too.
Based on these the markup for the web user control is:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="jQueryToggleExtender.ascx.cs"Inherits="JQueryCollapse.jQueryToggleExtender" %>
<asp:ScriptManagerProxy runat="server" ID="smp">
        <asp:ScriptReference Path="~/js/jquery-1.4.4.min.js" />
        <asp:ScriptReference Path="~/js/jquery-ui-1.8.8.custom.min.js" />
<wc:InlineScript runat="server" ID="inlineScripts">
    <script type="text/javascript">
        function pageLoad() {
            var collapsed = $get('<%= hfCollapsed.ClientID %>');

            $('#<%= ToggleControlID %>').click(
                function () {
                    if (collapsed.value == 1) {
                        $('#<%= ToggleImageID %>').attr('src', '<%= ExpandedImage %>');
                        $('#<%= ToggleTextID %>').text('<%= ExpandedText %>');
                    else {
                        $('#<%= ToggleImageID %>').attr('src', '<%= CollapsedImage %>');
                        $('#<%= ToggleTextID %>').text('<%= CollapsedText %>');

                    $('#<%= TargetControlID %>').toggle('blind', {}, 500);
                    collapsed.value = 1 - collapsed.value;

            if (collapsed.value == 1) {
                $('#<%= TargetControlID %>').hide();
                $('#<%= ToggleTextID %>').text('<%= CollapsedText %>').html();
                $('#<%= ToggleImageID %>').attr('src', '<%= CollapsedImage %>');
            } else {
                $('#<%= ToggleTextID %>').text('<%= ExpandedText %>').html();
                $('#<%= ToggleImageID %>').attr('src', '<%= ExpandedImage %>');
<asp:HiddenField runat="server" ID="hfCollapsed" />

We have to register our control in the web.config before using:

<?xml version="1.0"?>

  For more information on how to configure your ASP.NET application, please visit

                <!--Registering inline script-->
                <add tagPrefix="wc" assembly="JQueryCollapse" namespace="JQueryCollapse.WebServerControls" />
                <!--Registering toggle extender-->
                <add tagPrefix="wuc" tagName="Toggle" src="~/WebUserControls/jQueryToggleExtender/jQueryToggleExtender.ascx" />
        <compilation debug="true" targetFramework="4.0" />


A simple example page for testing:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JQueryCollapse.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>jquery toggle for</title>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <asp:UpdatePanel runat="server" ID="upMain">
            <asp:Button runat="server" ID="btnClickMe" Text="ClickMe" />
            <a id="hrefToggle" href="#" runat="server">
                <asp:Panel ID="pnToggle" runat="server" Width="100%" BackColor="Azure">
                    <asp:ImageButton runat="server" ID="imgCollapse" AlternateText="Click here to collapse or expand" />
                    <asp:Label runat="server" ID="lblCollapse"></asp:Label>
            <asp:Panel runat="server" ID="pnContent">
    <asp:Button runat="server" ID="btnPb" Text="Postback" />
    <br />
    <asp:Button runat="server" ID="btnCollapse" OnClick="btnCollapse_Click" Text="Toggle" />
    <wuc:Toggle runat="server" ID="tTest" TargetControlID="pnContent" ToggleControlID="hrefToggle"
        ToggleImageID="imgCollapse" ToggleTextID="lblCollapse" ExpandedText="Click here to collapse"
        ExpandedImage="Images/collapse.gif" CollapsedText="Click here to expand" CollapsedImage="Images/expand.gif"

And the code behind of the page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JQueryCollapse
    public partial class Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)

        /// <summary>
        /// Toggle the extender
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCollapse_Click(object sender, EventArgs e)
            tTest.Collapsed = !tTest.Collapsed;


And at last the full source code of the solution can be downloaded my public folder on skydrive.

Monday, 31 January 2011 web server control for rendering script blocks

There are many ways to add script block to our pages. This is a very simple problem until we had got a complex project with custom controls, partial page rendering, updatepanels and dynamically loaded controls.
We have to add script blocks different ways if we asynchrony post backs or full page post backs.
The other problem is when the script block don’t have to load at the first page load, it depends on some logic dynamically.

After many trying I use this solution since about half year and it works at any case.

The simple and easy to use source code is:

public class InlineScript : Control
        protected override void Render(HtmlTextWriter writer)
            StringBuilder sb = new StringBuilder();
            base.Render(new HtmlTextWriter(new StringWriter(sb)));

            string script = sb.ToString();

            ScriptManager sm = ScriptManager.GetCurrent(Page);
            if (!(null == sm))
                if (sm.IsInAsyncPostBack)
                    ScriptManager.RegisterStartupScript(this, typeof(InlineScript), UniqueID, script, false);
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ID, sb.ToString());

After registering into web.config, we can use it easily everywhere on our program:

<wc:InlineScript ID="isTest" runat="server">
    <script type="text/javascript">
        function pageLoad() {

Saturday, 29 January 2011

How to set up Windows 7 environment for PHP + MySQL development on IIS7

We need a following tools for an average PHP + MySql development procedure:

- a good IDE

- something for managing database

- web server

- ability to debugging applications

- get all of them free.

IDE: We need intellisense support and tools for debugging. Smart people doesn’t start any development without these. If you have Windows operating system, you can use Web Platform Installer and it offers a development environment named Webmatrix free of charge. Webmatrix doesn’t have debugger or intellisense support so it’s only a memory killer, good looking notepad. After some googling and based on my experiments I have been chosen Netbeans IDE.

Database Manager: I don’t use MySql too often so I let to choose my tool. I wanted a native sql IDE and found MySql Workbench. It doesn’t have too long feature list but we can do the basic SQL tasks and it is not PHPMyAdmin so we doesn’t need to run web browser for insert a simple record into our database.

Web server: I use Windows 7 and of course it will IIS7. I have been bought my Windows before and I can install it free of charge.


Installing IIS7: I won’t describe how to install it. There is a good description how to install it on IIS website.

Installing Netbeans IDE:

- Download from the php development version (or we can choose version named ALL, that will install every development tools from C to Java that netbeans supports).

- Install the executable. (Not too hard, next-next-next…..-finish).

- Navigate to PHP tab on Tools->Options on Netbeans menu. If we got ALL version, we have to make a new php project. In that case Netbeans initializes himself for php development and we will see PHP tab on Options->Tools after creating New PHP Project. If we installed the PHP version, we don’t need to make new PHP project, Netbeans initializes php settings during the first run.

- Check the php development settings. We need to set Debugger Port to 9000 and Session_ID to netbeans-xdebug for debugging php applications.

Installing Mysql

- Go to MySQL Download page.

- Download the proper version for our operating system (In my case it means Windows (x86, 32-bit), MSI Installer).

- Install the executable. (Not too hard, next-next-next…..-finish). We have to set security settings during the installation.

- Download MySql Workbench. We have to chose a version again.

- Install the executable. (Not too hard, next-next-next…..-finish).

- Start MySql Workbench and test if we can connect to our database. WorkbenchStartPage

Installing PHP binaries:

- Start Web Platform Installer. If doesn’t have, download and install it.

- Go to products tab, Frameworks entry and check PHP 5.3 for WebMatrix and PHP Manager for IIS.WebPlatformInstallerSelectItems

- Click on Install button.

- Installer shows us what will it install and what will it install more. We didn’t check WebMatrix but we have to install it. Click on Accept button. Ha must install it but don’t need to use this piece of shit.WebPlatformInstallerDependencies

- At the end of the installation Web Platform Installer shows us a message window and offers to run WebMatrix. Simple close the window, don’t need to start it.WebPlatformInstallerInstalComplete

- Install CGI Extension for IIS7:

  • Start Control Panel and go to Programs entry.
  • Click on Turn Windows features on or off entry.
  • Got to Information Services-World Wide Web Services->Application Development Feature and check CGI
  • Install it.

Installing xDebug:

- Start IIS7 manager.

- We can find PHP Manager on IIS section on IIS Manager.IISManagerPHPManagerIcon

- Click on Check phpinfo() link.


- Choose site and url.

- Start our browser and go to the home page of xDebug. There is a page named fnd binary on that site and it helps us deciding which xDebug version we need. There is a big, empty textbox in that page. Paste our phpinfo output into this textbox and click on Analyse my phpinfo() button. After analysed, the page offers the proper xDebug version for us. That means MS VC9 – Architecture: x86 in my case. After analyising this page offers a link direct to download page under Instructions.

- Download the proper dll and copy it to an ext subfolder to our php installation. At my case it means the folder c:\Program Files (x86)\PHP\v5.3\ext\ .

- Go back to PHP Manager on IIS and click on  Configuration file link and we can edit our php.ini settting file.

- Add the following lines to the end of the file:

- Restart IIS.

- Check phpinfo() again. If we installed xDebug successfully we will find a ‘… with xDebug…’ part of the output at the end of the first block of the html result of phpinfo that signs that our installation is successful.PHPInfoWithXDebug

At that point we don’t have any to do, only write our firs PHP application (of course a simple Hello World) and check if we can debug it and if we can connect to our MySql database.


Note: We have to use the same port at xDebug port in php.ini and netbeans-xdebug port in Netbeans settings. If we start a php project on debug mode in Netbeans and we have wrong port settings, we can’t debug and Netbeans cannot connect to xDebug process only shows a messange: Waiting for conncection (netbeans-xdebug).NetbeansWrongXDebugSettings

Saturday, 8 January 2011

C#: throwable exceptions and Visual Studio Productivity Power Tools


There is a really great add-on for Visual Studio named Productivity Power Tools. It helps a lot during my work but hides some information that so important for me: the list of throwable exceptions.

At the university I didn’t have a choice. I had to learn Java. Java is a great language and has a restriction that I like so: you must specify the list of the throwable exceptions at the specification of each method. I work with C# nowadays. It doesn’t has this rule but Visual Studio tries to help us on a simple way: it shows us this list when we hover on the name of the given method with the mouse like this:

As we can se, we now a bit closer to the Java restrictions. We can find out fast the given list but the language still don’t force us into handle all exceptions. It smart or not – I don’t know. But in fact I’m happy to see this list.

There is a bit problem with the power tools: It gives us a new window for our Visual Studio, named Solution Navigator. It has a lot of functions among others coloring the hints that I shown before:


Ops! As we can see, the list of throwable exceptions has disappeared. We have an other function instead of this, every can try this out by clicking on the triangle at the right side of the popup.

At this time we have two choice. We can use our Visual Studio with these settings or we can disable this function by setting of on the Visual Studio menu –> Tools –> Options –> Productivity Power Tools –> Solution Navigator. We got the original function after restarting our development environment.



Remarks: Solution Navigator is so slow. Sometimes useful but the most part of my times it only slows down my work without any benefits.

Monday, 3 January 2011

Sql server–Using indexes with LIKE operator in stored procedures


In the most cases msdn is a trusted source of information. Of course sometimes some mistakes are slipping into. The other day I read a documentation about CREATING STORED PROCEDURES when I found an interesting slip-up:

“Avoid using a wildcard as the leading character in a LIKE clause, for example, LIKE ‘%a%’. Because the first character is non-deterministic, the query processor is unable to use available indexes. Use LIKE ‘a%’ instead.”

Well, I thought there was a catch in it because I use the LIKE operator with leading wildcard in many cases and I know, we can get a significant speed increase with indexes in this case too.

I made a simple test using my Northwind database:

-- create sample stored procedure for demonstrate
-- the using of indexex with leading wildcards
create procedure SelectCustomers
as begin
    select * from Customers
    where CompanyName like 'a%'


-- running the example
exec SelectCustomers


-- delete the example
drop procedure SelectCustomers

After running I got the following result in my actual execution plan:


The conclusion about using indexes with LIKE operator is the following:

- without wildcards: Index seek (like ‘a’)

- with wildcards: Index scan (like ‘a%’, like ‘%a’, like ‘%a%’)