AJAX Interview Questions and Answers

What is AJAX?

  1. AJAX is an acronym for Asynchronous JavaScript and XML.
  2. AJAX is a new technique for creating better, faster, and more interactive web applications.
  3. With AJAX, a JavaScript script can communicate directly with the server, with the XMLHttpRequest object. With this object, a JavaScript can exchange data with a web server, without reloading the page.
  4. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of entire pages.
  5. The AJAX technique makes Internet applications smaller, faster and more user-friendly.

What is "AsyncPostBackTimeout" Property?

  1. AsyncPostBackTimeout Property specifies the time, in seconds, before an asynchronous postback timeout occurs if no response is received from the server.
  2. The default value of this property is 90 (seconds).
  3. We can also set the user defined error message using "asyncpostbackerrormessage" property (as shown in the code above) for the time out.
  4. For example:

    <asp:ScriptManager ID="scriptManager1" runat="server" AsyncPostBackErrorMessage="We can not serve your request at this moment. Please try later." AsyncPostBackTimeout="120">

    </asp:ScriptManager>

How to use Script Manager's "AsyncPostBackTimeout" at runtime?

  1. If you have a Script Manager on the Master page and need to exceed AsyncPostBackTimeout only on specific page, then
  2. Add this code line to the "Page_Load" event of your page.
  3. This will set the AsyncPostBackTimeout to 2 minutes.
  4. For example:
     

    ScriptManager _scriptMan = ScriptManager.GetCurrent(this);

    _scriptMan.AsyncPostBackTimeout = 120;

    OR

    ScriptManager.GetCurrent(this).AsyncPostBackTimeout = 120;

Is it possible to use a "FileUpload" control within the update panel?

  1. Yes, it's possible.
  2. But we need to use Postback triggers to upload the file.

Can you list some AJAX controls?

  1. ScriptManager
  2. ScriptManagerProxy
  3. Timer
  4. UpdatePanel
  5. UpdateProgress

What is the "DisplayAfter" property in the UpdateProgress control?

  1. The Displayafter property specifies how many seconds after loading the image that it needs to be displayed in the AJAX postback.
  2. In other words, it gets or sets the value in milliseconds before the UpdateProgress control is displayed.
  3. For example:

    In the following example, the "Loading" text will be displayed after 5 sec.
     

    <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="5000" 

      AssociatedUpdatePanelID="UpdatePanel1">

       <ProgressTemplate>

            Loading...

       </ProgressTemplate>

    </asp:UpdateProgress>

How can we detect asynchronous partial page postbacks?

  1. Use the "IsInAsyncPostBack" property of the "ScriptManager".
  2. It returns a boolean value that can be used to check for partial page postbacks.

Which two methods are used for handling Cross-Domain AJAX Calls?

  1. Cross-domain means the ability to manually or automatically access or transfer data between two or more differing security domains.
  2. Cross-Origin Resource Sharing (CROS): Works with all HTTP verbs and most modern web browsers. Provides better support for error handling than JSONP.
  3. JSON with padding (JSONP): It only works with HTTP GET verb and on legacy browsers.

What is the limitation with update panel?

  1. Using update panel, you cannot validate outside controls.
  2. For example:

    There is a grid in an update panel and you want to validate the grid's field having a button outside the update panel. Validation will be executed but does not affect the page due to the update panel. So to solve this kind of problem, we have placed a button in another update panel.

What is "PageMethod" in ASP.Net AJAX?

  1. The "PageMethods" feature enables the use of code-behind page methods on the client side.
  2. PageMethods are implemented in a code behind file.
  3. These are public static methods and are annoted with a [WebMethod] attribute.
  4. The PageMethods can only be added to the page itself so don't try to add them to user controls or custom controls, it won't work.
  5. Basically, all you need to do in order to use a PageMethod is to decorate your page method with the ScriptMethod and WebMethod attributes or only with the WebMethod attribute.
  6. Another restriction is that the method has to be static (or else it won't work).
  7. For example:

    [WebMethod]

    public static string GetLabelText()

    {

       return "Hello";

    }

     

     

    <scripttype="text/javascript">

       function InsertLabelData() {

            PageMethods.GetLabelText(onSuccess, onFailure);

        }

     

       function onSuccess(result) {

           var lbl = document.getElementById('lbl');

            lbl.innerHTML = result;

        }

     

       function onFailure(error) {

            alert(error);

        }

     

        InsertLabelData();

    </script> 

Up Next
    Ebook Download
    View all
    Learn
    View all