Oct 31, 2015

Sql Server

Sql Server page is dedicated to database related stuff and blog post.

Please looking related post for Sql Server related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

Other

Other is dedicated to rest of the blog post. It meant other then display in menu section.

Please looking related post for other then Asp.Net, AngularJs and jQuery related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

Contact Us

Kalpesh Satasiya
satasiya.kalpesh2006@gmail.com
Mob: +91 94283 22329
India

jQuery

jQuery page is dedicated to jQuery related blog post.

Please looking related post for jQuery related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

AngularJs

Angular page is dedicated to AngularJs related stuff and blog post.

Please looking related post for AngularJs related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

Asp.Net

Asp.Net page is dedicated to Microsoft technologies related blog post.

Please looking related post for Asp.Net / Microsoft technologies related post under the "Related Post" section.

Hope you like those posts and please keep reading blog.
Please give your suggestions and comments for blog improvement.

jQuery restrict text length for textarea on keypress event

Recently I am facing issues for textarea is not supported to max length attribute to tag.
So I need to do manually restrict allow max length character using jQuery keypress event.

Here we have one textarea and define id as txtcomment. so I am going to attached keypress event for textarea.

So when we are try to write anything under that textarea it will fire the keypress event on jQuery side.

Let's see example of keypress event and how to handle text length for any input control.
 
function restrictLenght()
{
    var tval = $('#txtcomment').val(),
        return tval.length < 250;
}

When you start writing under textarea it will allow you to write only 256 character.

Why I have return this blog because many developer does not know about this feature is not supported by textarea by default.

Hope this post help to you. Please keep reading my blog post and help to improve this blog.


Oct 28, 2015

What is difference between Service, Factory and Provider in AngularJS


Many developer are confused related service, factory and provider terminology in AngularJs. why and were we need to use those features. Little confusion on all three functionality/feature because of as normal way we can say similar functionality but not.

I have already written post related AngularJs Dependency Injection and that post covered difference between service, factory and provider.

So Please visit my previous post and get difference with example.



Oct 27, 2015

What is difference between Convert.ToString() and .ToString()

Its a simple question for experienced C#/Asp.Net developer but its little confusing things for beginner.

Convert.ToString() generally used when we need to handle null value. it meant when data as null and used Convert.ToString() its return blank string.
Convert.ToString() handles null, while ToString() doesn't.

Oct 23, 2015

New domain for blog www.tech-coder.com

I'm pleased to inform you that I have brought new domain for my blog and that is www.tech-coder.com 

www.tech-coder meant technical coder which you serve technical related information now onword.

Till date technical related information served by my blog (www.satasiyakalpesh.blogspot.com) and now it's redirect to www.tech-coder.com.

Oct 21, 2015

Asp.Net show gridview header when there is no data or empty

Recently I have facing gridview header display issues when DataSource is empty or null.

So for same i have googing and find the solution like how to show header even DataSource is empty or null.

Before I was written the blog post, think it like it's a chunk of code but might be useful to someone who facing the same issue.

Generally, writing the condition to check any DataTable, DataSet, List or any collection have data then we assign to that collection/DataTable to GridView DataSource.

So let's see example. How to create and assign dummy table to DataSource then display the header without any data record.
if (dt.rows.count > 0)
{ 
    grdview.DataSource = dt;
    grdview.DataBind();
}
else
{

    var dummyTable = new DataTable();
     dummyTable.Columns.Add("Column1");
        dummyTable.Columns.Add("Column2");
        dummyTable.Rows.Add(dummyTable.NewRow());
        grdview.DataSource = dummyTable;
        grdview.DataBind();
        grdview.Rows[0].Style.Add(HtmlTextWriterStyle.Display, "none");
}

Hope you would like it and please share your suggestions and comments for improvement.

Oct 17, 2015

Dependency Annotation In AngularJs


Previous post we were talking about Dependency Injection in AngularJs so today also talk about AngularJs stuff related to Dependency Annotation.

AngularJs invokes certain services, factories and controllers via the injector. So its a best practices to annotate these functions. it meant that the injector knows what services to inject into the function.

There are three ways of annotating your code with service name information:
  1. Inline array annotation
  2. $inject property annotation
  3. Implicitly from the function parameter name
Inline Array Annotation This is the preferred way to annotate application components. Let's us see example.
//define a module
var mainApp = angular.module("mainApp", []);

mainApp.controller('MathsFunController', ['$scope', 'mathService', function($scope, mathService) {
     // ...
}]);

Here we pass an array whose elements consist of a list of strings (the names of the dependencies) followed by the function itself.

When using this type of annotation, take care to keep the annotation array in sync with the parameters in the function declaration.

$inject Property Annotation
$inject To allow the minifiers to rename the function parameters and still be able to inject the right services, so function needs to be annotated with the $inject property.

The $inject property work like array so its hold the service name to inject.
//define a module
var mainApp = angular.module("mainApp", []);

var MathsFunController = function($scope, mathService) {
  // ...
}
MathsFunController.$inject = ['$scope', 'mathService'];
mainApp.controller('MathsFunController', MathsFunController);

Implicit Annotation
Careful: If you plan to minify your code, your service names will get renamed and break your app.
The is the simplest way to inject the dependencies because of dependencies is to assume that the function parameter names are the names of the dependencies.
//define a module
var mainApp = angular.module("mainApp", []);

mainApp.controller('MathsFunController', function($scope, mathService{
  // ...
});
Above a function, the injector can refer the names of the servies to inject  at function declaration and extracting the parameter names.

Given example, $scope and mathService are two services which need to be injected into the function.

One advantage of this approach is that there's no array of names to keep in sync with the function parameters. You can also freely reorder dependencies.

However one disadvantage of this approach will not work with JavaScript minifiers/obfuscators because of how they rename parameters.

So recommend avoiding this approach of annotation.

Hope you get idea about Dependency Annotation in AngularJs.

Please share your suggestions and comment for improvement.

Oct 15, 2015

AngularJS Dependency Injection

Today I am talking about Dependency Injection (DI) and how to work in AngularJs. Let's start with definition of Dependency Injection.

Definition of DI:
Dependency Injection is a software design pattern in which components are given their dependencies instead of hard coding them within the component. This replace a component from finding the dependency and makes dependencies configurable. This helps in making components reusable, maintainable and testable. 

How to DI work with AngularJs:
AngularJS provides a great Dependency Injection mechanism. It provides following list of core components which can be injected into each other as dependencies.

  1. value
  2. factory
  3. service
  4. provider
  5. constant
Value
value is simple JavaScript object/var and it is used to pass values to controller during config phase.
//define a module
var mainApp = angular.module("mainApp", []);
//create a value object as "defaultValue" and pass it a value.
mainApp.value("defaultValue", 5);
//inject the value in the controller using its name "defaultValue"
mainApp.controller('MathsFunController', function($scope,  defaultValue) {
$scope.number = defaultValue;
});
Factory
factory is a function which is used to return value. It creates value on demand whenever a service or controller requires. It normally uses a factory function to calculate and return the value.

//define a module
var mainApp = angular.module("mainApp", []);
//create a factory "MultiplyService" which provides a method multiply to return multiplication of two numbers
mainApp.factory('MultiplyService', function() {
   var factory = {};   
   factory.multiply = function(a, b) {
      return a * b
   }
   return factory;
}); 
//inject the factory "MultiplyService" in a service to utilize the multiply method of factory.
mainApp.service('MathService', function(MultiplyService){
   this.square = function(a) {
      return MultiplyService.multiply(a,a);
   }
});

Service
service is a singleton JavaScript object containing a set of functions to perform certain tasks. Services are defined using service() functions and then injected into controllers.


//define a module
var mainApp = angular.module("mainApp", []);
//create a service which defines a method square to return square of a number.
mainApp.service('MathService', function(MultiplyService){
   this.square = function(a) {
      return MultiplyService.multiply(a,a); 
   }
});
//inject the service "MathService" into the controller
mainApp.controller('MathsFunController', function($scope, MathService, defaultValue) {
   $scope.number = defaultValue;
   $scope.result = MathService.square($scope.number);   
   $scope.square = function() {
      $scope.result = MathService.square($scope.number);
   }
});

Provider
provider is used by AngularJS internally to create services, factory etc. during config phase. following script can be used to create MultiplyService that I have created earlier. Provider is a special factory method with a method get() which is used to return the value/service/factory.
//define a module
var mainApp = angular.module("mainApp", []);
//create a service using provider which defines a method square to return square of a number.
mainApp.config(function($provide) {
   $provide.provider('MultiplyService', function() {
      this.$get = function() {
         var factory = {};           
         factory.multiply = function(a, b) {
            return a * b; 
         }
         return factory;
      };
   });
});

Constant
constants are used to pass values at config phase considering the fact that value can not be used to be passed during config phase.
mainApp.constant("configParam", "constant value");

Hope AngularJs lover clear some idea of  AngularJs Dependency Injection work with different component and how to inject it.

And I want also discuss regarding $inject Property but will cover on next blog. So please keep reading and give your suggestions and comments will be highly appreciated.

Oct 14, 2015

Node.js has been released new stable version v4.2.0

This post for Node.js lover. If they have not know about Node.js has release new version v4.2.0 couple of days ago.

Following features are added/updated on new release v4.2.0 version of Node.js:

Node.js  v4.2.0 "Argon" releases has introduced a naming convention based on the Periodic Table of Elements that applies only to LTS releases

New release has been improvement of significant performance.

For more detail of what's new and updated in Node.js v4.2.0 version.
Please visit official website of Node.js or release page information.

Oct 13, 2015

How to install Go lang and configure IntelliJ IDEA IDE for Go

Today I am going to talk about installation for Go lang and how to configure IDE IntelliJ IDEA for same.

Following are the steps to ready to work with Go
  1. So first start with download of Go executable package from the official website
  2. Once download GO installer
  3. Run executable package and install into the system.
  4. Going all the way to the end by clicking "next", c:/go/bin will be added to path
  5. Once complete installation go to the open command line.
  6. Type 'Go' and hit enter so you will see look like below image (Sometime not getting below screen than re-start your system and try again)
  7.  Now go to environment variables and find the GOROOT (C:\Go\) variable added by installer
  8. We need to add one more variable manually in environment variables
  9. Add new variable name GOPATH and set path your workspace (i.e D:\Work\GoWorkSpace)
  10. Now we are done Go environment setup so start for IDE configuration.
  11. Download IntelliJ IDEA IDE and install it
  12. Open IDE and install Go plugin for same.
  13. Choose File - Setting - Plugins, than click Browser repo.
  14.  Search golang,  double click download and install  and wait for the download to complete.
  15. Sometime golang not getting search from Browser repo, then you will do manually download plugin and install from 'Install Plugin from disk'
  16. Now click apply, then restart.
  17. Now we are ready to use IDE for Go Project.
  18. Next for step for setup go sdk path which basically your GOROOT path.
Hope you are getting idea how to install and configure to ready Go.

Oct 12, 2015

Custom directives in AngularJs

We will talk about AngularJs Custome directive.

Already AngularJs is packed with powerful directives, but we want to create our own directive for reusable functionality.
In this blog, we will focus on how to handle the easy way to complex process of creating directives.

First we will start with AngularJs own directives and explain the process further in blog.

Before start making your own directive, first you need to understand what directives actually.
In AngularJs directives are core functionality that will run when the DOM is compiled by the compiler.

AngularJs directives such as ng-click, ng-show/ng-hide, ng-repeat,and many others will get from AngularJs core script.

Even build-in directives cover many scenarios but sometime we need to custom directives for different scenario.

So let's time to start for custom directives but before going forward I assume that you already know the basic AngularJs and what directives are and how they are used.

First fall we talk about how many way we can define directives. following are the ways to define and use directives.

1) As an attribute: (Restrict option : 'A')
<div custom-directives></div>

2) As a class: (Restrict option : 'C')
<div class="custom-directives : expression;"></div>
3) As an element: (Restrict option : 'E')
<custom-directive></custom-directive>
4) As a comment: (Restrict option : 'M')
< !--directive: custom-directive expression  -->
So let's time to  go through some example's

angular.module('directivesModule').directive('ngCustomDirective', function () {
                return {
                    restrict: 'A', //E = element, A = attribute, C = class, M = comment
                    template: 'Name: {{customer.name}}
City: {{customer.city}}'
                };
            });


 How to invoke above directive code in html. see below html snippet.
<div ng-customdirective></div>

 
You have notice one thing when we invoke it, directives name is not same as we define ( ngCustomDirective  vs ng-customedirective). This is because AngularJS will handle translating the camel cased name when we define it to the snake case when we invoke it.

Output of above directive invoke:
Name: Kalpesh
City: Ahmedabad

Hope you get idea about custom directive.