Ajax Interview Questions
 
Q: How can you to add JavaScript to a page when performing an asynchronous postback?
Ans : Use the ScriptManager class. This class contains several methods like the RegisterStartupScript(), RegisterClientScriptBlock(), RegisterClientScriptInclude(), RegisterArrayDeclaration(),RegisterClientScriptResource(), RegisterExpandoAttribute(), RegisterOnSubmitStatement() which helps to add javascript while performing an asynchronous postback.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Explain differences between the page execution lifecycle of an ASP.NET page and an ASP.NET AJAX page?
Ans : In an asynchronous model, all the server side events occur, as they do in a synchronous model. The Microsoft AJAX Library also raises client side events. However when the page is rendered, asynchronous postback renders only the contents of the update panel, where as in a synchronous postback, the entire page is recreated and sent back to the browser.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Is the ASP.NET AJAX Control Toolkit(AjaxControlToolkit.dll) installed in the Global Assembly Cache?
Ans : No. You must copy the AjaxControlToolkit.dll assembly to the /Bin folder in your application. Those were some frequently asked questions you should have knowledge about. In one of the coming articles, we will cover some more ASP.NET AJAX FAQ’s which were not covered in this article. I hope this article was useful and I thank you for viewing it.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is Ajax?
Ans : The term Ajax was coined by Jesse James Garrett and is a short form for "e;Asynchronous Javascript and XML"e;. Ajax represents a set of commonly used techniques, like HTML/XHTML, CSS, Document Object Model(DOM), XML/XSLT, Javascript and the XMLHttpRequest object, to create RIA's (Rich Internet Applications). Ajax gives the user, the ability to dynamically and asynchronously interact with a web server, without using a plug-in or without compromising on the user’s ability to interact with the page. This is possible due to an object found in browsers called the XMLHttpRequest object.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is ASP.NET AJAX?
Ans : ASP.NET AJAX’ is a terminology coined by Microsoft for ‘their’ implementation of AJAX, which is a set of extensions to ASP.NET. These components allow you to build rich AJAX enabled web applications, which consists of both server side and client side libraries.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Which is the current version of ASP.NET AJAX Control Toolkit?
Ans : As of this writing, the toolkit version is Version 1.0.20229 (if you are targeting Framework 2.0, ASP.NET AJAX 1.0 and Visual Studio 2005) and Version 3.0.20229 (if targeting .NET Framework 3.5 and Visual Studio 2008).
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What role does the ScriptManager play?
Ans : The ScriptManager manages all ASP.NET AJAX resources on a page and renders the links for the ASP.NET AJAX client libraries, which lets you use AJAX functionality like PageMethods, UpdatePanels etc. It creates the PageRequestManager and Application objects, which are prominent in raising events during the client life cycle of an ASP.NET AJAX Web page. It also helps you create proxies to call web services asynchronously.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Can we use multiple ScriptManager on a page?
Ans : No. You can use only one ScriptManager on a page.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is the role of a ScriptManagerProxy?
Ans : A page can contain only one ScriptManager control. If you have a Master-Content page scenario in your application and the MasterPage contains a ScriptManager control, then you can use the ScriptManagerProxy control to add scripts to content pages. Also, if you come across a scenario where only a few pages in your application need to register to a script or a web service, then its best to remove them from the ScriptManager control and add them to individual pages, by using the ScriptManagerProxy control. That is because if you added the scripts using the ScriptManager on the Master Page, then these items will be downloaded on each page that derives from the MasterPage, even if they are not needed, which would lead to a waste of resources.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What are the requirements to run ASP.NET AJAX applications on a server?
Ans : You would need to install ‘ASP.NET AJAX Extensions’ on your server. If you are using the ASP.NET AJAX Control toolkit, then you would also need to add the AjaxControlToolkit.dll in the /Bin folder. Note: ASP.NET AJAX 1.0 was available as a separate downloadable add-on for ASP.NET 2.0. With ASP.NET 3.5, the AJAX components have been integrated into ASP.NET
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Explain the UpdatePanel?
Ans : The UpdatePanel enables you to add AJAX functionality to existing ASP.NET applications. It can be used to update content in a page by using Partial-page rendering. By using Partial-page rendering, you can refresh only a selected part of the page instead of refreshing the whole page with a postback.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Can I use ASP.NET AJAX with any other technology apart from ASP.NET?
Ans : To answer this question, check out this example of using ASP.NET AJAX with PHP, to demonstrate running ASP.NET AJAX outside of ASP.NET. Client-Side ASP.NET AJAX framework can be used with PHP and Coldfusion.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Difference between Server-Side AJAX framework and Client-side AJAX framework?
Ans : ASP.NET AJAX contains both a server-side Ajax framework and a client-side Ajax framework. The server-side framework provides developers with an easy way to implement Ajax functionality, without having to possess much knowledge of JavaScript. The framework includes server controls and components and the drag and drop functionality. This framework is usually preferred when you need to quickly ajaxify an asp.net application. The disadvantage is that you still need a round trip to the server to perform a client-side action. The Client-Side Framework allows you to build web applications with rich user-interactivity as that of a desktop application. It contains a set of JavaScript libraries, which is independent from ASP.NET. The library is getting rich in functionality with every new build released.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How can you debug ASP.NET AJAX applications?
Ans : Explain about two tools useful for debugging: Fiddler for IE and Firebug for Mozilla.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Can you nest UpdatePanel within each other?
Ans : Yes, you can do that. You would want to nest update panels to basically have more control over the Page Refresh.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is XmlHttpRequest in Ajax?
Ans : It is an object in Javascript that allows the browser to communicate to a web server asynchronously without making a postback.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Can Ajax be implemented in browsers that do not support the XmlHttpRequest object?
Ans : Yes. This is possible using remote scripts.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: an AJAX technology work on web servers other than IIS?
Ans : Yes, AJAX is a technology independent of web server the web application is hosted on. Ajax is a client (browser) technology. .
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Which browsers support the XmlHttpRequest object?
Ans : Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0/Firefox, Opera 8.0 +, Netscape 7 . .
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to we create an XmlHttpRequest object for Internet Explorer? How is this different for other browsers?
Ans : For Internet Explorer, an ActiveXObject is used for declaring an XmlHttpRequest object in Javascript.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What are the properties of the XmlHttpRequest object? What are the different types of readyStates in Ajax?
Ans : A - i) onreadyStateChange - This function is used to process the reply from the web server. ii) readyState - This property holds the response status of the web server. There are 5 states: 0 - request not yet initialized 1 - request now set 2 - request sent 3 - request processing 4 - request completes iii) responseText - Has the data sent back by the web server Code snippet below shows an example how these there properties are used to implement ajax : xmlHttpObject.onreadystatechange=function() { if(xmlHttpObject.readyState==4) { document.Form1.time.value=xmlHttpObject.responseText; } }
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is the role of ScriptManager in Ajax?
Ans : ScriptManager class is the heart of ASP.NET Ajax. Before elaborating more on ScriptManager, note that ScriptManager is class and a control (both) in Ajax. The ScriptManager class in ASP.NET manages Ajax Script Libraries, partial page rendering functionality and client proxy class generation for web applications and services. By saying client proxy class, this means an instance of the Ajax runtime is created on the browser. This class is defined in the System.Web.Extensions.dll. You will find this DLL in your system's Global Assembly Cache at C:\Windows\Assembly (For XP) The ScriptManager control (that we may drag on a web form) is actually an instance of the ScriptManager class that we put on a web page. The ScriptManager manages all the ASP.NET Ajax controls on a web page. Following tasks are taken care by the ScriptManager class: 1 - Managing all resources (all objects/controls) on a web page 2 - Managing partial page updates 3 - Download Ajax Script Library to the client (means to the browser). This needs to happen so that Ajax engine is accessible to the browsers javascript code. 4 - Interacting with UpdatePanel Control, UpdateProgress Control. 5 - Register script (using RegisterClientScriptBlock) 6 - Information whether Release OR Debug script is sent to the browser 7 - Providing access to Web service methods from the script by registering Web services with the ScriptManager control 8 - Providing access to ASP.NET authentication, role, and profile application services from client script after registering these services with the ScriptManager control 9 - Enable culture specific display of clientside script. 10 - Register server controls that implement IExtenderControl and IScriptControl interfaces. ScriptManager class' EnablePartialRendering property is true by default.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Whats the difference between RegisterClientScriptBlock, RegisterClientScriptInclude and RegisterClientScriptResource?
Ans : A - For all three, a script element is rendered after the opening form tag. Following are the differences: 1 - RegisterClientScriptBlock - The script is specified as a string parameter. 2 - RegisterClientScriptInclude - The script content is specified by setting the src attribute to a URL that points to a script file. 3 - RegisterClientScriptResource - The script content is specified with a resource name in an assembly. The src attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What are type/key pairs in client script registration? Can there be 2 scripts with the same type/key pair name?
Ans : When a script is registered by the ScriptManager class, a type/key pair is created to uniquely identify the script.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What is an UpdatePanel Control?
Ans : An UpdatePanel control is a holder for server side controls that need to be partial postbacked in an ajax cycle. All controls residing inside the UpdatePanel will be partial postbacked. Below is a small example of using an UpdatePanel.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: What are limitations of Ajax?
Ans : An Ajax Web Application tends to confused end users if the network bandwidth is slow, because there is no full postback running. However, this confusion may be eliminated by using an UpdateProgress control in tandem. 2) Distributed applications running Ajax will need a central mechanism for communicating with each other
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: Which request is better with AJAX, Get or Post?
Ans : AJAX requests should use an HTTP GET request while retrieving data where the data does not change for a given URL requested. An HTTP POST should be used when state is updated on the server. This is in line with HTTP idempotency recommendations and is highly recommended for a consistent web application architecture.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com

Q: How to control how long an Ajax request may last?
Ans : Use the ScriptManager's AsyncPostBackTimeout Property. For example, if you want to debug a web page but you get an error that the page request has timed out, you may set <asp:ScriptManager id="e;ScriptManager1"e; runat="e;server"e; AsyncPostBackTimeout="e;9000"e;/> where the value specified is in seconds.
Date submitted :8/8/2009 1:03:38 AM
Submitted by : shabir@myfaithsolution.com