Quick Tip – Empty a JavaScript Array

Friday, September 20, 2013

Quick Tip – Empty a JavaScript Array The question of how to empty an array in JavaScript is being raised from time to time. If you will look at the JavaScript array API you will find that the array objects in JavaScript don’t include an empty/remove function. How to Empty an Array? The Allocation Way The first answer that I occasionally see is to allocate a new array: var a = ;   // later in code ...
no comments

Quick Tip – Including Empty Directory While Deploying a Web Application

Wednesday, May 18, 2011

Quick Tip – Including Empty Directory While Deploying a Web Application During this week I had to deploy an ASP.NET MVC 3 web application to a host environment using web deploy. The problem I faced was the deployment of an empty directory which is being used by the application. By design, when using web deploy tool in Visual Studio it skips empty directories when packaging a web application. So How can you deploy this empty directory and overcome this problem? The solution is to put an empty stub file in the directory you want to deploy. Just create an empty...
no comments

Quick Tip – Disable/Enable Button by Textbox Client Event using jQuery

Thursday, September 16, 2010

Quick Tip – Disable/Enable Button by Textbox Client Event using jQuery I find myself often with a need to disable/enable a button according to client events that occur on web pages. Today I helped to implement this behavior again so I thought it will be nice to share the code I used. In this example I’m disabling/enabling a button according to whether a textbox holds some text. I’m using jQuery to make the code simple. Pay attention that this solution can be implemented for other events also. The Code $(document).ready(function () { $('#txtAgentName').blur(function () { ...
no comments

Discover which Control Raised a PostBack

Monday, March 1, 2010

Discover which Control Raised a PostBack Yesterday I needed a solution for an annoying problem. I have some buttons on a ASP.NET web form and I need to know which button raised the postback not in the event itself but in the page load event. This post will show a way to solve this conundrum. Discover which Control Raised a PostBack When we use ASP.NET and we have ASP buttons on the page if we want to do something before their postback event happen we need to discover whether they raised a postback. Since an ASP button uses the form.submit() method on the...
5 comments

CompiledQuery in Entity Framework

CompiledQuery in Entity Framework There are times when we want to make optimizations on some piece of code. If we want to reduce the cost of executing a query in Entity Framework we can use a CompiledQuery to the rescue. Yesterday I used added a compiled query to a code base which was executing multiple times. This reduced the execution time of the repeating queries. In the post I’ll explain what are CompiledQueries and how to use them. CompiledQuery CompiledQueries are a delegate which store a compiled LINQ query that we have built in advance. When we use them we can reduce...

The Regulator

Tuesday, February 2, 2010

The Regulator Yesterday, I reviewed a regular expression that was written by one of the developers and I needed to improve it since it wasn’t performing the appropriate thing. Since I know The Regulator tool, I opened it and in 5 minutes I came up with this regular expression which validate Israeli phone/cellular numbers: ^0(5|6|){1}(\-)?{1}\d{6}$ With The Regulator I created and checked the expression and then implemented it in the application. What is The Regulator? The Regulator is a free tool that was written by Roy Osherove. It’s purpose is to help us create regular expressions and also to test them inside...
one comment

Applying Strategy Pattern Instead of Using Switch Statements

Sunday, November 22, 2009

Applying Strategy Pattern Instead of Using Switch Statements Once in a while I’m stumbling on switch statements during a Code Review session. Whenever this is happening my first reaction is to understand why did the developer use it. Since using switch statement sometime implies spaghetti code and also can get very crowded (in case statements of course) in this post I’m going to show an alternative method that I prefer to use. Alternative Method for Switch Statements Whenever you start to use a switch statement you should ask yourself whether you can use Strategy Pattern instead. The Strategy Pattern help us to...

Back to Basics – How to Invoke Web Methods from a Remote Machine

Sunday, November 8, 2009

Back to Basics – How to Invoke Web Methods from a Remote Machine I’ve been asked today how to enable invocation of WebMethods of an asmx web service from a remote machine for testing. The post holds the answer. How to Invoke Web Methods from a Remote Machine? Sometimes we want to test our asmx web service not from localhost but from a remote machine. Trying to open the test form of the web service from a remote machine will show the following message: “The test form is only available for requests from the local machine”. In order to enable the...

Quick Tip – Adding Business Validation Messages to ValidationSummary

Friday, September 11, 2009

Quick Tip – Adding Business Validation Messages to ValidationSummary Two days ago I was asked how to insert business validation messages into a ValidationSummary control. The post is the answer I gave to the person who asked me. The Problem We have a web form that is doing input validation and output the errors inside a ValidationSummary control. Since ValidationSummary shows a summary of all validation errors from ASP.NET validators how can we add business validations which are part of the business logic we have to the output of the ValidationSummary ? Also, how can we make the input not valid according...
no comments

Quick Tip – How to Enable Local Cache in Velocity (Microsoft Distributed Cache) Client

Thursday, July 16, 2009

Quick Tip – How to Enable Local Cache in Velocity (Microsoft Distributed Cache) Client Since I got this question twice this week, I’m writing this post. One of Velocity (Microsoft Distributed Cache) features is called local cache. In this post I’ll show how to enable that feature. Velocity Client Local Cache Local cache is a Velocity feature that can help speed up access on Velocity clients. When enabled, a de-serialized...