Friday, August 8, 2014

A very simple example on System.Reflection in Asp.net

Today I will show you a very simple example on Reflection.

Follows the steps:

Step 1. Create a project with asp.net empty web application and name it "ReflectApp".

Step 2. Create a web form in it and paste following code and run it.

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, 
                            ByVal e As System.EventArgs) Handles Me.Load
        Dim currentAppName = System.Reflection.Assembly.Load("ReflectApp")

        For Each type As Type In currentAppName.GetTypes
            If type.Name = "Customer" Then
                Dim o As Object = Activator.CreateInstance(type)

                Dim mInfo As System.Reflection.MethodInfo = type.GetMethod("getName")

                If mInfo IsNot Nothing Then
                    Dim result As String = mInfo.Invoke(o, Nothing)

                    Response.Write(result)
                End If

                Exit For
            End If

        Next 
    End Sub
    Public Class Customer
        Private Property _Name As String

        Sub New()
            _Name = "John Miller"
        End Sub

        Public Function getName() As String
            Return _Name
        End Function

    End Class

End Class


Result will be: John Miller

You can debug and see how it works.

Thursday, August 7, 2014

Wednesday, August 6, 2014

Explain with example ISNULL, NULLIF and COALESCE in SQL Server


ISNULL : Replaces NULL with the specified replacement value.

NULLIF : Returns a null value if the two specified expressions are equal.

COALESCE : Returns the first non-null argument.(msdn: Evaluates the arguments in order and returns the current value of the first expression that initially does not evaluate to NULL).

Here are the examples and it's results:

SELECT ISNULL(null,1)
--Result: 1

SELECT NULLIF(1,1)
--Result: NULL

SELECT COALESCE(1,null,null,null)
--Result: 1

SELECT COALESCE(null,2,3,4)
--Result: 2

SELECT COALESCE(null,null,3,4)
--Result: 3

SELECT COALESCE(null,null,null,4)
--Result: 4

SELECT ISNULL(NULLIF(COALESCE(null,null,null,4),4),1)
--Result: 1


Tuesday, August 5, 2014

A very simple example on KnockoutJS in Asp.net

Today I will show you a very simple example on KnockoutJS in Asp.net

Please follows the steps:

Step 1: Create a project with Asp.net empty web application and add web form.

Step 2: Now, paste following code in "body" tag of your aspx page.
<body>
     
    <p>First name: <strong data-bind="text: firstName"></strong></p>
    <p>Last name: <strong data-bind="text: lastName"></strong></p>
    <p>
        First name:
            <input data-bind="value: firstName" />
    </p>
    <p>
        Last name:
            <input data-bind="value: lastName" />
    </p>
    <script
        src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js">
    </script>
    <script>

        function AppViewModel() {
            this.firstName = ko.observable("John");
            this.lastName = ko.observable("Miller");
        }

        // Activates knockout.js
        ko.applyBindings(new AppViewModel());
    </script>
</body>


Now run your web form and try to change first name, it will automatically change the first name in the label as well.

Monday, August 4, 2014

How to bind dynamically HTML Ordered List in Asp.net using AngularJS?

Today I will show you a very simple example on binding HTML Ordered List dynamically in Asp.net using AngularJS.

Follows the steps:

Step 1: Create a project with asp.net empty web application and add web form in it.

Step 2: Now, paste following code in ".aspx" page
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div ng-app="" ng-controller="itemController">
            <ol>
                <li ng-repeat="item in items">{{ item }}
                </li>
            </ol>
        </div>

        <script>
            function itemController($scope) {
                $scope.items = [<%=items%>];
            }

        </script>
        <script 
            src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">

        </script>

    </form>
</body>
</html>


Step 3: Now, paste following code in ".aspx.vb" code behind page
Public Class WebForm1
    Inherits System.Web.UI.Page

    Public items As String = ""

    Protected Sub Page_Load(ByVal sender As Object,
                            ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            'You can change this items dynamically '
            items = "'Orange', 'Apple', 'Banana', 'Grape', 'Watermelon'"
        End If

    End Sub

End Class


Result will be:

1.Orange
2.Apple
3.Banana
4.Grape
5.Watermelon


Friday, August 1, 2014

How to check or compare that two dates, not including time, are equal? in Asp.net

A very simple example of comparing two dates without including time as below:

One Way:
Dim date1 As Date = CDate("8/1/2014 11:00:00 PM")
Dim date2 As Date = CDate("8/1/2014 02:25:15 AM")

Dim result As Boolean = date1.Date.Equals(date2.Date)
'Result: True


Second Way:
Dim date1 As Date = CDate("8/1/2014 11:00:00 PM").ToShortDateString()
Dim date2 As Date = CDate("8/1/2014 02:25:15 AM").ToShortDateString()

Dim result As Boolean = Date.Equals(date1, date2)
'Result: True 


React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to ...