All About ASP.NET and ASP.NET Core 2 Hosting BLOG

Tutorial and Articles about ASP.NET and the latest ASP.NET Core

ASP.NET Hosting - :: How to Call ASP.NET Page Methods using your own AJAX

clock March 15, 2016 20:04 by author Armend

ASP.NET has grown very rich day by day. Recently Microsoft has introduced JQuery as a primary javascript development tool for client end application. Even though there is a number of flexibility in ASP.NET AJAX applications, many developers do seek place to actually call a page using normal AJAX based application. In this post I will cover how you can invoke an ASP.NET page method directly from your own AJAX library.

What are page methods?

A Page method is a method that is written directly in a page. It is generally called when the actual page is posted back and some event is raised from the client. The pageMethod is called directly from ASP.NET engine.

What is a WebMethod?

A WebMethod is a special method attribute that exposes a method directly as XML service. To implement PageMethod we first need to annotate our method as WebMethod.
Steps to Create the application :
1. Start a new ASP.NET Project.
2. Add JQuery to your page. I have added a special JQuery plugin myself which stringify a JSON object. The post looks like below :

(function ($) {
toJson: function (obj) {
var t = typeof (obj);
if (t != "object" || obj === null) {
// simple data type
if (t == "string") obj = '"' + obj + '"';
return String(obj);
else {
// recurse array or object
var n, v, json = [], arr = (obj && obj.constructor == Array);
for (n in obj) {
v = obj[n]; t = typeof (v);
if (t == "string") v = '"' + v + '"';
else if (t == "object" && v !== null) v = JSON.stringify(v);
json.push((arr ? "" : '"' + n + '":') + String(v));
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
// extend plugin scope
toJson: $.toJson.construct

The code actually extends JQuery to add a method called toJSON to its prototype.

3. Add the server side method to the Default.aspx page. For simplicity we actually return the message that is received from the client side with some formatting.

public static string DisplayTime(string message)
// Do something
return string.Format("Hello ! Your message : {0} at {1}", message, DateTime.Now.ToShortTimeString());

Remember : You should make this method static, and probably should return only serializable object.

4. Add the following Html which actually puts one TextBox which takes a message and a Button to call server.

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
Welcome to ASP.NET!
Write Your message Here : <input type="text" id="txtMessage" />
<input type="button" onclick="javascript:callServer()" value="Call Server" />
Once you add this html to your default.aspx page, add some javascript to the page. We add the JQuery and our JSONStringify code to it.
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/JSONStringify.js" type="text/javascript"></script>
<script type="text/javascript">
function callServer() {
var objdata = {
"message" : $("#txtMessage").val()
type: "POST",
url: "Default.aspx/DisplayTime",
data: $.toJson(objdata),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
error: function (xhr, ajaxOptions) {

The above code actually invokes a normal AJAX call to the page. You can use your own library of AJAX rather than JQuery to do the same. On success, it returns the serializable object to msg.d.

ASP.NET Hosting - :: Entity Framework 7 Providing support for new platforms

clock March 8, 2016 20:40 by author Armend

EF (Entity Framework) is Microsoft's flagship data access platform -- an extended ORM (Object Relational Mapper) that abstracts the calls to the ADO.Net data access provider underneath. It is an open source ORM framework for ADO.Net and is included as part of .Net Framework. The first version of Entity Framework (EFv1) was released as part of .Net Framework 3.5 Service Pack 1 and Visual Studio 2008 Service Pack 1 in the year 2008.

In using Entity Framework, you can work with relational data using domain-specific objects. Entity Framework has been the technology of choice for building data access layer while working with WPF, WinForms, MVC, WebAPI, WebForms and WCF applications. Here are a few design documents on Entity Framework 7.
The latest version of this ORM is Entity Framework 7. Microsoft's vision for Entity Framework 7 is "New Platforms, New Data Stores". This implies that Entity Framework 7 is an extensible and lightweight version of Entity Framework that enables provides support for new platforms and new data stores. Entity Framework 7 is a major redesign of Entity Framework and is the default data stack for ASP.Net 5 applications.

I would like to highlight some of the striking features of EF7 in this post. To get started working with Entity Framework 7 you should add the Entity Franework 7 NuGet packages to your project.
Here's quick glance at what's new in Entity Framework 7:

  • Support for non-relational data stores and in-memory data
  • Support for Windows Phone and Windows Store applications
  • Support for Linux and Macintosh machines

Support for non-relational data stores and in-memory data

NoSQL databases are widely popular these days primarily because of performance -- CRUD operations on these database are faster compared to their relational counterparts. NoSQL databases are a good choice when you have to work with a large volume of data - particularly useful in statistical or real-time analysis of data. Entity Framework 7 now provides support for non-relational databases as well. The support for no-SQL in Entity Framework 7 is great. Interestingly, for querying and updating data in non-relational databases, you can use the same approach you are familiar with.
The following code snippet illustrates how you can use Entity Framework 7 with Microsoft Azure Table Storage to initialize a connection to the database.

public class StoresContext : DbContext
  protected override void OnConfiguring(DbContextOptions options)
   var connection =

The supported providers in Entity Framework 7 include:

  • SQL Server
  • SQLit
  • Azure Table Storage
  • Redis
  • In Memory (for unit testing)

Support for Windows Phone, Windows Store applications and Linux and Macintosh platforms

With Entity Framework 7, Windows Phone, Windows Store and ASP.Net 5 and desktop applications can leverage Entity Framework. Entity Framework 7 would work on SQLLite database -- the database of choice for mobile devices. Entity Framework 7 also provides support for Linux and Macintosh systems where Mono framework has been installed.

Entity Framework 7 is Lightweight and Extensible

Entity Framework 7 is lightweight and extensible -- it comes with more features and flexibility and enhanced performance. Another major change will be the "code first only" approach -- all models in Entity Framework 7 will be represented in the code. You would however be able to reverse engineer a model from the underlying database thanks to the tooling support. Code based modeling is preferred as it is less repetitive and easier to use and manage.

Enhanced support for Unit testing

Unit testing allows you to test blocks or units of the source code. Unit testing is simpler with EntityFramework 7. The code snippet given below shows a sample unit test.

public void SampleTest()
var options = new DbContextOptions()
using (var db = new StoresContext(options))
//Code to perform CRUD operations
//Assert the results

Effort is an easy to use and powerful unit testing tool for applications that use Entity Framework. It is actually an ADO.Net provider that comes with some helper methods that enables you to execute the CRUD operations on a lightweight in-memory database for faster execution. Effort is an Entity Framework provider that runs in memory. When writing your unit tests you can still use your familiar DbContext or ObjectContext classes. Most importantly, you are not constrained to have an actual database – your unit tests would be executed against the in-memory database.

Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions

Author Link

 photo ahp banner aspnet-01_zps87l92lcl.png


Corporate Address (Location)

170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in