Ajax.Pro Introduction

Hello, Everyone!

There are plenty of ways to implement AJAX functionality in web application e.g. raw XMLHTTP object, ASP.NET AJAX, Ajax.Pro, JQuery, Prototype js etc.

Here i am writing for How to use Ajax.Pro in our application.

Ajax.Pro is not itself a framework, but it is just a DLL provided by http://www.ajaxpro.info. This DLL is used to make asynchronous calls to ASP.NET server-side class.

To use, Ajax.Pro we have to add add reference of AjaxPro DLL in the project.

Then, add following lines to web.config:

<configuration>
<system.web>
<httpHandlers>
<!-- Register the ajax handler -->
<add verb="POST,GET" path="ajax/*.ashx"
type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>
</system.web>
</configuration>

The above lines register the HTTP handler to handle the ajax requests created by Ajax.Pro.

Now, register the class whose methods need to be called from the client-side JavaScript. Here, in my sample code, I have registered my class as:

AjaxPro.Utility.RegisterTypeForAjax(typeof(Sample));

Now, decorate the Server-side class method with the [AjaxMethod] attribute. By decorating our class method by this attribute, the method can be called from client-side ajax. In my Sample I have decorated my AddPerson method with AjaxMethod attribute as follows:

[AjaxMethod]
public string AddPerson(string firstName, string lastName, string email)
{
      Your code goes here....
}

That’s it. This is what you need to implement AJAX.Pro.

SSL and XMLHTTP Object

Hello Everyone,

This is very useful information when you implement ssl in site which is implemented using Ajax.

When you attempt to access a secure URL by using the XMLHTTP request object from a script on a non-secure Web page, you may receive one of the following error messages:

With Msxml2.XMLHTTP:
Permission Denied

With Microsoft.XMLHTTP:
Access is Denied

This problem only occurs if a non-secure page attempts to access a secure page. Accessing a secure page from another secure page does not generate an error.

Communication between javascript and .Net CLR

Hi All,

I am presenting article on communication between javascript and .Net CLR. There are number of methods for the same. In this article, we will see how to communicate javascript and .Net CLR using webservice.

I have used javascript object for communication with server side method because this is a good practice to use javascript object instead of list of argument. And you can also see how javascript object will be used in communication with server side method.

Below code representing that how can we pass the information from client side to server side?

function Employee(firstName, lastName, age)
{
   Employee.prototype.firstName = firstName;
   Employee.prototype.lastName = lastName;
   Employee.prototype.age = age;
}

function insertEmployeeClick()
{
   var firstName = document.getElementById("txtFirstName").value;
   var lastName = document.getElementById("txtLastName").value;
   var age = document.getElementById("txtAge").value;

   if (firstName == "") { alert("First Name    Required");document.getElementById("txtFirstName").focus();return;}
   if (lastName == "") { alert("Last Name Required"); document.getElementById("txtLastName").focus(); return; }
   if (age == "") { alert("Age Required"); document.getElementById("txtAge").focus(); return; }

   var employee = new Employee(firstName, lastName, age);
   JSObject.InsertEmployee(employee, onInsertCallBack);
}

function onInsertCallBack(result)
{
   document.getElementById("txtFirstName").value = "";
   document.getElementById("txtLastName").value = "";
   document.getElementById("txtAge").value = "";

   if (result) { alert("Employee added successfully"); }
   else { alert("Database insert fail"); }
}

I have also attached the sample code. You can download it from here.
JSObjectAndWebService

 

Ajax Pro problem in medium trust environment

Hello Everyone,

This is very useful information for guys, who are using Ajax Pro.  If you are using ajax with lower version of ajax dll (e.g “5.6.3.4”) in medium trust environment then you will face security problem and your application will not work in medium trust. You can resolve this problem by using latest version of ajax dll (e.g. 6.7.20.1, 6.10.6.1, 9.2.17.1 etc).

Generally you are facing this kind of problem in shared hosting environment where you can not change the trust level of your application.