Monday, February 11, 2008

Interview Questions

Q. What exactly happens when aspx page is requested from browser?

A. At its core, the ASP.NET execution engine compiles the page into a class, which derives from the code behind class (which in turn derives directly or indirectly from the Page class). Then it injects the newly created class into the execution environment, instantiates it, and executes it. ASP.NET, on the other hand, can accept code in any language that is compatible with the .NET framework, because it's compiled down natively just like other code

Q. What is the order of destructors called in a polymorphism hierarchy?

A. Destructors are called in reverse order of constructors. First destructor of most derived class is called followed by its parent’s destructor and so on till the topmost class in the hierarchy.
You don’t have control over when the first destructor will be called, since it is determined by the garbage collector. Sometime after the object goes out of scope GC calls the destructor, then its parent’s destructor and so on. When a program terminates definitely all object’s destructors are called.


Q. can we have two web.config files in a single project(web allplication)?

A. The answer is yes, you can have 2 web.config file under the same project. Look at the page below to know the answer

Q. How can you enable automatic paging in datagrid?

A. Using the Built-In Paging Controls To use default paging, you set properties to enable paging, set the page size, and specify the style of the paging controls. Paging controls are LinkButton controls. You can choose from these types: Next and previous buttons. The button captions can be any text you want. Page numbers, which allow users to jump to a specific page. You can specify how many numbers are displayed; if there are more pages, an ellipsis ( ? ) is displayed next to the numbers. You must also create an event-handling method that responds when users click a navigation control. To use the built-in paging controlsSet the control's AllowPaging property to true. Set the PageSize property to the number of items to display per page. To set the appearance of the paging buttons, include a element into the page as a child of the DataGrid control. For syntax, see DataGrid Control Syntax. Create a handler for the grid's PageIndexChanged event to respond to a paging request. The DataGridPageChangedEventsArgs enumeration contains the NewPageIndex property, which is the page the user would like to browse to. Set the grid's CurrentPageIndex property to e.NewPageIndex, then rebind the data.



Q. if a.equals(b) is true then a.gethashcode() and b.gethashcode() must always return same hash code


A. The answer is False because it is given that A.equals(B) returns true i.e. objects are equal and now its hashCode is asked which is always independent of the fact that whether objects are equal or not. So, GetHashCode for both of the objects returns different value.



Q. what is text stream object?

A. It facilitates sequential access to file. The property and method arguments can be any of the properties and methods associated with the TextStream object. Note that in actual usage TextStream is replaced by a variable placeholder representing the TextStream object returned from the FileSystemObject. Example In the following code, a is the TextStream object returned by the CreateTextFile method on the FileSystemObject: Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("c:testfile.txt", True) a.WriteLine("This is a test.") a.Close WriteLine and Close are two methods of the TextStream Object.


Q. how do you differentiate managed code and unmanaged code?

A. Managed Code
is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer.Managed code runs in the Common Language Runtime.
Unmanaged code
is what you use to make before Visual Studio .NET 2002 was released.It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same.

Q. What is the difference between EVENTS and FUNCTIONS?

A. Event represents an action that is done to an object whereas Function represents an action that the object itself is doing.


Q. what events will occur when a page is loaded?

A. Page_PreInit Page_Init Page_InitComplete Page_PreLoad


Q. How can we create custom controls in asp.net?

A. Custom Controls can be created in either of the following 3 methods. Creating as a composite control : This method uses and combines the existing controls to give a custom functionality which can be used across different projects by adding to the control library. This can provide for event bubbling from child controls to the Parent container, custom event handling and properties. The CreateChildControls function of the Control class should be overridden for creating this custom control. This can also support design time rendering of the control. Deriving from an existing control : This method of creating a custom control derives from an existing ASP .Net control and customizing the properties that we need. This also can support custom event handling, properties etc. Creating a control from Scratch : This method is the one which needs maximum programming. This method needs even the HTML code for the custom controls to be written by the programmer. This may also need one to implement the IPostBackDataHandler and IPostBackEventHandler interfaces. A detailed explanation with example for this is available at Rendering Custom Controls Sample in MSDN.


Q. What is the difference between login controls and forms authentication?

A. Login controls are an easy way to implement Forms authentication without having to write any code. For example, the Login control performs the same functions you would normally perform when using the FormsAuthentication class prompt for user credentials, validate them, and issue the authentication ticket but with all the functionality wrapped in a control that you can just drag from the Toolbox in Visual Studio. Under the covers, the login control uses the FormsAuthentication class (for example, to issue the authentication ticket) and ASP.NET membership (to validate the user credentials). Naturally, you can still use Forms authentication yourself, and applications you have that currently use it will continue to run.


Q. Difference between webconfig and machineconfig?

A. Web.config file, as it sounds like is a configuration file for the Asp .net web application. An Asp .net application has one web.config file which keeps the configurations required for the corresponding application. Web.config file is written in XML with specific tags having specific meanings. As web.config file is used to configure one asp .net web application, same way Machine.config file is used to configure the application according to a particular machine. That is, configuration done in machine.config file is affected on any application that runs on a particular machine. Usually, this file is not altered and only web.config is used which configuring applications.


Q. what is the use of fixed statement?

A. The fixed statement sets a pointer to a managed variable and “pins” that variable during the execution of statement. Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably. (In fact, the C# compiler will not allow you to set a pointer to a managed variable except in a fixed statement.) Eg: Class A { public int i; } A objA = new A; // A is a .net managed type fixed(int *pt = &objA.i) // use fixed while using pointers with managed variables { *pt=45; // in this block use the pointer the way u want }

Q.Is it possible to override private virtual methods?

A. No, First of all you cannot declare a method as ‘private virtual’.

Q. how to load data from one page to another page in asp.net?

A . There are many ways to do this? In Asp.net2.0 You can use cross page submission. Using Query String Using Post

Q. What does the volatile modifier do?

A. The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment. The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.


Q. .What is the use of AutoWireup in asp.net? In which circumstances we have to use this?


A .AutoEventWireup attribute is used to set whether the events needs to be automatically generated or not. If AutoEventWireup is set to "false" see that the page related events are not fired. For example if you write Response.Write("hello world") in the Page_Load event when the AutoEventWireup="false" then the Response.Write.. is not executed. However, when we set the value of the AutoEventWireup attribute to true, the ASP.NET runtime does not require events to specify event handlers like Page_Load or Page_Init.

What is a Webcontrol?

Serves as the base class that defines the methods, properties and events common to all controls in the System.Web.UI.WebControls namespace.


Q. what is the difference between application state and caching

Application variable is the global variable specific to application but a caching variable is specifc to page and time out.

Q. What can be stored in webconfig file

There are number of important settings that can be stored in the configuration file. Here are some of the most frequently used configurations, stored conveniently inside Web.config file.. 1. Database connections 2. Session States 3. Error Handling 4. Security

No comments: