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:
    1. <asp:ScriptManager ID="scriptManager1" runat="server" AsyncPostBackErrorMessage="We can not serve your request at this moment. Please try later." AsyncPostBackTimeout="120">  
    2. </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:
    1. ScriptManager _scriptMan = ScriptManager.GetCurrent(this);  
    2. _scriptMan.AsyncPostBackTimeout = 120;  

    OR

    1. 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.
    1. <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="5000"   
    2.   AssociatedUpdatePanelID="UpdatePanel1">  
    3.    <ProgressTemplate>  
    4.         Loading...  
    5.    </ProgressTemplate>  
    6. </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:
    1. [WebMethod]  
    2. public static string GetLabelText()  
    3. {  
    4.    return "Hello";  
    5. }  
    1. <script type="text/javascript">  
    2.    function InsertLabelData() {  
    3.         PageMethods.GetLabelText(onSuccess, onFailure);  
    4.     }  
    5.    function onSuccess(result) {  
    6.        var lbl = document.getElementById('lbl');  
    7.         lbl.innerHTML = result;  
    8.     }  
    9.    function onFailure(error) {  
    10.         alert(error);  
    11.     }  
    12.     InsertLabelData();  
    13. </script>

More Interview Questions


Similar Articles