Friday 22 April 2011

ASP.Net Interview Q & A




1. Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
Ans:  inetinfo.exe is the Microsoft IIS server running, handling ASP.NET requests among other things. When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tithe actual worker process aspnet_wp.exe.
 
2. What’s the difference between Response.Write() andResponse.Output.Write()?
Ans: 
Response.Output.Write() allows you to write formatted output.
 
3. What methods are fired during the page load?
Ans: 
Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.
 
4. When during the page processing cycle is View State available?
Ans:  After the Init() and before the Page_Load(), or OnLoad() for a control.
 
5. What namespace does the Web page belong in the .NET Framework class hierarchy?
Ans: 
System.Web.UI.Page
 
6. Where do you store the information about the user’s locale?
Ans: 
System.Web.UI.Page.Culture
 
7. What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
Ans: 
CodeBehind is relevant to Visual Studio.NET only.
 
8. What’s a bubbled event?
Ans: 
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
 
9. Suppose you want a certain ASP.NET function executed on MouseOver for a certain button.  Where do you add an event handler?
Ans: 
Add an OnMouseOver attribute to the button.  Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");
 
10. What data types do the RangeValidator control support?
Ans:
    Integer, String, and Date.
 
11. Explain the differences between Server-side and Client-side code?
Ans: 
Server-side code executes on the server.  Client-side code executes in the client's browser.
 
12. What type of code (server or client) is found in a Code-Behind class?
Ans: 
The answer is server-side code since code-behind is executed on the server.  However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser.  But just to be clear, code-behind executes on the server, thus making it server-side code.
 
13. Should user input data validation occur server-side or client-side?  Why?
Ans: 
All user input data validation should occur on the server at a minimum.  Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.
 
14. What is the difference between Server.Transfer and Response.Redirect?  Why would I choose one over the other?
Ans: 
Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser.  This provides a faster response with a little less overhead on the server.  Server.Transfer does not update the clients url history list or current url.  Response.Redirect is used to redirect the user's browser to another page or site.  This perform as a trip back to the client where the client's browser is redirected to the new page.  The user's browser history list is updated to reflect the new address.
 
15. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
Ans: 
Valid answers are:
1.  A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
2.  A DataSet is designed to work without any continuing connection to the original data source.
3.  Data in a DataSet is bulk-loaded, rather than being loaded on demand.
4. There's no concept of cursor types in a DataSet.
5.  DataSets have no current record pointer You can use For Each loops to move through the data.
6.  You can store many edits in a DataSet, and write them to the original data source in a single operation.
7. Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.
 
16. What is the Global.asax used for?
Ans:    The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.  
17. What are the Application_Start and Session_Start subroutines used for?
Ans: 
This is where you can set the specific variables for the Application and Session objects. 
18. Can you explain what inheritance is and an example of when you might use it?
Ans: 
When you want to inherit (use the functionality of) another class.  Example: With a base class named Employee, a Manager class could be derived from the Employee base class. 
19. What’s an assembly?
Ans: 
Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN 
20. Describe the difference between inline and code behind.
Ans: 
Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page. 
21. Explain what a diffgram is, and a good use for one?
Ans: 
The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML.  A good use is reading database data to an XML file to be sent to a Web Service. 
22. What’s MSIL, and why should my developers need an appreciation of it if at all?
Ans: 
MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.  MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer. 
23. Which method do you invoke on the DataAdapter control to load your generated dataset with data?
Ans: 
The Fill() method. 
24. Can you edit data in the Repeater control?
Ans: 
No, it just reads the information from its data source. 
25. Which template must you provide, in order to display data in a Repeater control?
Ans: 
ItemTemplate. 
26. How can you provide an alternating color scheme in a Repeater control?
Ans: 
Use the AlternatingItemTemplate. 
27. What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?
Ans:
    You must set the DataSource property and call the DataBind method. 
28. What base class do all Web Forms inherit from?
Ans: 
The Page class.
 
29. Name two properties common in every validation control?
Ans: 
ControlToValidate property and Text property. 
30. Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
Ans: 
DataTextField property.  
31. Which control would you use if you needed to make sure the values in two different controls matched?
Ans: 
CompareValidator control.  
32. How many classes can a single .NET DLL contain?
Ans: 
It can contain many classes. 
33. What is the transport protocol you use to call a Web service?
Ans: 
SOAP (Simple Object Access Protocol) is the preferred protocol.  
34. True or False: A Web service can only be written in .NET?
Ans: 
False  
35. What does WSDL stand for?
Ans: 
Web Services Description Language. 
36. Where on the Internet would you look for Web services?
Ans: 
http://www.uddi.org 
37. True or False: To test a Web service you must create a Windows application or Web application to consume this service?
Ans: 
False, the web service comes with a test page and it provides HTTP-GET method to test
38. What is ViewState?
Ans: 
ViewState allows the state of objects (serializable) to be stored in a hidden field on the page.  ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.  ViewState is used the retain the state of server-side objects between postabacks.  
39. What is the lifespan for items stored in ViewState?
Ans: 
Item stored in ViewState exist for the life of the current page.  This includes postbacks (to the same page).
 
40. What does the "EnableViewState" property do?  Why would I want it on or off?
Ans: 
It allows the page to save the users input on a form across postbacks.  It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser.  When the page is posted back to the server the server control is recreated with the state stored in viewstate.
 
41. What are the different types of Session state management options available with ASP.NET?
Ans: 
ASP.NET provides In-Process and Out-of-Process state management.  In-Process stores the session in memory on the web server.  This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server.  Out-of-Process Session state management stores data in an external data source.  The external data source may be either a SQL Server or a State Server service.  Out-of-Process state management requires that all objects stored in session are serializable.
42. Which controls do not have events?
Ans:
    Timer control.

43. What is the maximum size of the textbox?
Ans: 
65536.

44. Which property of the textbox cannot be changed at runtime?
Ans: 
Locked Property.
45. Which control cannot be placed in MDI?
Ans: 
The controls that do not have events.

46. Difference between a sub and a function.
Ans:-
  A Sub Procedure is a method will not return a value
-A sub procedure will be defined with a “Sub” keyword
Sub ShowName(ByVal myName As String)
Console.WriteLine(”My name is: ” & myName)
End Sub

-A function is a method that will return value(s).
-A function will be defined with a “Function” keyword
Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim sum As Integer = num1 + num2
Return sum
End Function

47. Explain manifest & metadata.
Ans: 
Manifest is metadata about assemblies. Metadata is machine-readable information about a resource, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.

48. Difference between imperative and interrogative code
Ans.
  There are imperative and interrogative functions and I think they are talking about that. Imperative functions are the one which return a value while the interrogative functions do not return a value.

49. What are the two kinds of properties
Ans.
  Two types of properties in .Net: Get & Set
Two kind of properties are scalar properties and indexed properties

50. Explain constructor
Ans: 
Constructor is a method in the class which has the same name as the class (in VB.Net its New()). It initializes the member attributes whenever an instance of the class is created.

51. Describe ways of cleaning up objects
Ans.
  The run time will maintain a service called as garbage collector. This service will take care of deallocating memory corresponding to objects, it works as a thread with least priority. When application demands for memory the runtime will take care of setting the high priority for the garbage collector, so that it will be called for execution and memory will be release. The programmer can make a call to garbage collector by using GC class in system name space.

52. What are value types and reference types?
Ans.
  Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap

53. How can you clean up objects holding resources from within the  code?
Ans: 
Call the dispose method from code for clean up of objects

54. Explain the life cycle of an ASP .NET page.
Ans: 
Life cycle of ASP.Net Web Form
Page Request >> Start >> Page Init >> Page Load >> Validation >> PostBack Event Handling >> Page Rendering >> Page Unload
Page Request - When the page is requested ASP.Net determines whether the page is to be parsed and compiled or a cached verion of the page is to be sent without running the page.
Start - Page propertied REQUEST and RESPONSE are SET, if the page is pastback request then the IsPostBack property is SET and in addition to this UICulture property is also SET.
Page Initilization - In this the UniqueID of each property is SET.  If the request was postback the data is not yet loaded from the viewstate.
Page Load - If it was a postback request then the data gets loaded in the control from the ViewState and control property are set.
Validation - If any control validation present, they are performed and IsValid property is SET for each control.
PostBack Event Handling - If it was a postback request then any event handlers are called.
Page Rendering - Before this the viewstate is saved from the page and RENDER method of each page is called.
Page Unload - Page is fully rendered and sent to the client(Browser) and is discarded. Page property RESPONSE and REQUEST are unloaded.

55. What is .Net architecture?
Ans: 
The order starting from the bottom
1. CLR (Common Language Runtime)
2. .Net framework base class
3. ASP.Net Web Form / Windows Form
56.  What are object-oriented concepts?
Ans.
Object Oriented concept includes the following:
1. Inheritance
2. Abstraction
3. Polymorphism
4. Encapsulation
57.  How do you create multiple inheritance in c# and .NET?
Ans.
  Use interfaces
public class MyTest: IPaidInterface, ISoldInterface

58.  When is web.config called?
Ans.
   Web.config is an xml configuration file. It is never directly called
unless we need to retrieve a configurations setting.

59.  How many weg.configs can an application have?
Ans.
   One.

60.  How do you set language in weg.config?
Ans.
   defaultLanguage=”vb”: This specifies the default code language.
debug=”true”: This specifies that the application should be run in debug
mode

61.  What does connection string consist of?
Ans.
    Server, user id, password, database name.

62.  Where do you store connection string?
Ans.
    Web.config
63.  What is abstract class?
Ans.
   An abstract class is a class that cannot be instantiated. Its purpose is
to act as a base class from which other classes may be derived.

64.  What is difference between interface inheritance and class inheritance?
Ans.
    We can only inherit from one class but multiple interfaces. In addition, an interface does not contain any implementation it just contains a series of signatures.

65.  What are the collection classes?
Ans.
   Queue, Stack, BitArray, HashTable, LinkedList, ArrayList, Name
ValueCollection, Array, SortedList , HybridDictionary, ListDictionary, StringCollection, StringDictionary

66. What are the types of threading models?
Ans.
   Single Threading: This is the simplest and most common threading model where a single thread corresponds to your entire application’s process.

Apartment Threading (STA): This allows multiple threads to exist in a single application. In single threading apartment (STA), each thread is isolated in its own apartment. The process may contain multiple threads (apartments) however when an object is created in a thread (i.e. apartment) it stays within that apartment. If any communication needs to occur between different threads (i.e. different apartments) then we must marshal the first thread object to the second thread. Free Threading: The most complex threading model. Unlike STA, threads are not confined to their own apartments. Multiple treads can make calls to the same methods and same components at the same time.

67. What inheritance does VB.NET support?
Ans.
   Single inheritance using classes or multiple inheritance using interfaces.

68.  What is a runtime host?
Ans.
   The runtime host is the environment in which the CLR is started and managed.

69.  Describe the techniques for optimizing your application?
Ans:
   The techniques for optimizing the application are:
1.  Avoid round-trips to server. Perform validation on client.
2. Save viewstate only when necessary.
3. Employ caching.
4. Leave buffering on unless there is a dire need to disable it.
5. Use connection pooling.
6.  Use stored procedures instead of in-line SQL or dynamic SQL.

70.  Differences between application and session
Ans.
   The session object maintains state on a per client basis whereas the application object is on a per application basis and is consistent across all client requests.

71.  What is web application virtual directory?
Ans.
   A virtual directory appears to client browsers as though it were contained in a Web server’s root directory, even though it can physically Reside somewhere else.

72.  What is isPostback property?
Ans:
    This property is used to check whether the page is being loaded and accessed for the first time or whether the page is added in response to the client postback.
Example:-
Consider two combo boxes
In one lets have a list of countries
In the other, the states.
Upon selection of the first, the subsequent one should be populated in
accordance. So this requires postback property in combo boxes to be true.

73.  Where do you store connection string?
Ans.
   Database connection string can be stored in the web config file. The connection string can be stored in the web.config file under element

74.  What does connection string consist of?
Ans.
   The connection string consists of the following parts:
In general:
Server: Whether local or remote.
Uid: User Id (sa-in sql server)
Password: The required password to be filled-in here
Database: The database name.

75.  What are the collection classes?
Ans.
   The .NET Framework provides specialized classes for data storage and retrieval.  These classes provide support for stacks, queues, lists, and hash tables.

76.  What is isPostback property?
Ans.
   This property is used to check whether the page is being loaded and accessed for the first time or whether the page is loaded in response to the client postback.
Example:
Consider two combo boxes. In one let’s have a list of countries. In the other, the states. Upon selection of the first, the subsequent one should be populated in accordance. So this requires postback property in combo boxes to be true.

77.  What are Abstract base classes?
Ans.
    Abstract Class is nothing but a true virtual class. This class cannot be instantiated instead it has to be inherited.
The method in abstract class are virtual and hence they can be overridden in the child class.

78. What is difference between interface inheritance and class inheritance?
Ans.
   Interface inheritance: -
1. The accessibility modifier in Interface is public by default.
2. All the methods defined in the interface class should be overridden in the child class.
Class Inheritance -
1. There is not restriction on the accessibility modifier in a class.
2. Only the method that are defined virtual should be overridden.

79.  ASP.NET OBJECTS?
Ans.
    Application,Request,Responce,server and session

80.  How do you get the value of a combo box in Javascript?
Ans.
   document.form_name.element_name.value

81.  Why do we use Option Explicit?
Ans::
Correct answer is - This statement force the declaration of variables in VB before using them.

82.  How do you create a recordset object in VBScript?
Ans.
//First of all declare a variable to hold the Recordset object,
ex-Dim objRs
//Now, Create this variable as a Recordset object, ex-
Set objRs=Server.CreateObject(ADODB.RECORDSET)

83.  What is a class in CSS?
Ans.
   A class allows you to define different style characteristics to the same HTML element, class is a child to the id, id should be used only once, a css class can be used multiple times:
div id=”banner”
p class=”alert”

84.  When inserting strings into a SQL table in ASP what is the risk and how can you prevent it?
Ans.
    SQL Injection, to prevent you probably need to use Stored Procedures  instead of inline/incode SQL

85. What is boxing? what is unboxing? what is deep copy & shallow copy?
Ans.
    Converting the value type into reverence type is call boxing.  When an object of value type is assigned with another, the data itself is copied from one object to another. Suppose there are two integer variables, count1 and count2. Further suppose that count1 contains the value 5 and that count2 is assigned the value of count1.
count1 = 5;
count2 = count1;
Both count1 and count2 now contain their own copies of the data, in this case, the value 5. They are independent. If count1 is now assigned the value 6, count2 will still contain the value 5. This type of copy is referred to as a deep copy. The value itself is copied.
If count1 is now assigned the value 6, count2 will still contain the value 5. This type of copy is referred to as a deep copy.
For reference types copies work differently. Remember that a reference type consists of two parts: the data on the heap and the address of the data stored in the reference variable itself on the stack. When one reference variable is assigned to another, the address stored in the first is copied to the second. They both then refer to the same data content on the heap. This is referred to as a shallow copy.

86.  What will be output for the given code?
Dim I as integer = 5
Do
I = I + 2
Response.Write (I & \” \”)
Loop Until I > 10
Ans.   o/p: It generates error because of \” \”. (VB.NET)

4 comments: