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.

No comments:

Post a Comment

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 ...