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