Using ASP.Net C# class object in Javascript and Web Service
Download sample
Introduction
This sample demonstrates how you can use an an ordinary ASP.Net C# class instance as an object in Javascript. We can expose C# object to Javascript using web services. This sample first gets employee details from MS Access database using ADO.Net. Then use it to initiate Employee object and return it in a web method. Download attached sample and run it with Visual Studio 2010.Sourcecode Explanation
- Employee.cs contains declaration for Employee class.
- EmployeeWebService.asmx.cs is a webservice file. It contains Web
Methods that are used to initiate Employee object and return it.
- Above web methods are used in Javascript inside Default.aspx page source. In order to consume web service in Javascript, we need to add reference to web service in Default.aspx source.
- Now call web service methods in Javascript code declared in Default.aspx.
No comments:
Post a Comment