Showing posts with label Interview Tips. Show all posts
Showing posts with label Interview Tips. Show all posts

Monday, August 10, 2009

Asp.Net Interview Question

ASP.NETInterview Questions
=========================



  1. Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
    inetinfo.exe is theMicrosoft 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 tothe actual worker process aspnet_wp.exe.

  2. What’s the difference between Response.Write() andResponse.Output.Write()?
    Response.Output.Write() allows you to write formatted output.

  3. What methods are fired during the page load?
    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 ViewState available?
    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?
    System.Web.UI.Page

  6. Where do you store the information about the user’s locale?
    System.Web.UI.Page.Culture

  7. What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
    CodeBehind is relevant to Visual Studio.NET only.

  8. What’s a bubbled event?
    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?
    Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");

  10. What data types do the RangeValidator control support?
    Integer, String, and Date.

  11. Explain the differences between Server-side and Client-side code?
    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?
    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?
    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?
    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 performas 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?
    Valid answers are:
    ·
    A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
    · A DataSet is designed to work without any continuing connection to the original data source.
    · Data in a DataSet is bulk-loaded, rather than being loaded on demand.
    · There's no concept of cursor types in a DataSet.
    · DataSets have no current record pointer You can use For Each loops to move through the data.
    · You can store many edits in a DataSet, and write them to the original data source in a single operation.
    · 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?
    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?
    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?
    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. Whats an assembly?
    Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN

  20. Describe the difference between inline and code behind.
    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?
    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. Whats MSIL, and why should my developers need an appreciation of it if at all?
    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?
    The Fill() method.

  24. Can you edit data in the Repeater control?
    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?
    ItemTemplate.

  26. How can you provide an alternating color scheme in a Repeater control?
    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?
    You must set the DataSource property and call the DataBind method.

  28. What base class do all Web Forms inherit from?
    The Page class.

  29. Name two properties common in every validation control?
    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?
    DataTextField property.

  31. Which control would you use if you needed to make sure the values in two different controls matched?
    CompareValidator control.

  32. How many classes can a single .NET DLL contain?
    It can contain many classes.


Web Service Questions

  1. What is the transport protocol you use to call a Web service?
    SOAP (Simple Object Access Protocol) is the preferred protocol.

  2. True or False: A Web service can only be written in .NET?
    False

  3. What does WSDL stand for?
    Web Services Description Language.

  4. Where on the Internet would you look for Web services?
    http://www.uddi.org

  5. True or False: To test a Web service you must create a Windows application or Web application to consume this service?
    False, the web service comes with a test page and it provides HTTP-GET method to test.


State Management Questions

  1. What is ViewState?
    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.

  2. What is the lifespan for items stored in ViewState?
    Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

  3. What does the "EnableViewState" property do? Why would I want it on or off?
    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.

  4. What are the different types of Session state management options available with ASP.NET?
    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.

Useful Techniques in Asp.Net

1. Finding the particular Data from the Dataset,Its Row Position and Current Page in Grid
====================================================================================
DataSet dsQuoteList = objQuote.GetQuoteBankList();

Giving a constraints to the first column that is the ID primary key like:

dsQuoteList.Tables[0].Constraints.Add("pk", dsQuoteList.Tables[0].Columns[0], true);

Now,

The below code will find the perticular ID int the given dataset and return new Datarow..

DataRow dr = dsQuoteList.Tables[0].Rows.Find("10540");

Now finding the Row position (RowIndex) in the Dataset, like..:

int RowIndx = int.Parse(dsQuoteList.Tables[0].Rows.IndexOf(dr).ToString()

Finally, You will get the exact position of particular Data in the Dataset.

In Addition You can also find the Current Page in the Datagrid or GridView after getting Datarow:

int PageSize = 10;

double CurrPage = Math.Ceiling(Convert.ToDouble(int.Parse(dsQuoteList.Tables[0].Rows.IndexOf(dr).ToString()) / PageSize ));

Done..

That's it !

2. Find the Exact words from string
==================================

using System.Text;
using System.Text.RegularExpressions;

Write in the Button Click Event :

private void button1_click(object sender, EventArgs e)
{
string strInput = "Hello World I am Here with the new sunrise";
string strOutput = FindFirstWords(strInput, 4);

// Here the result of strOutput variable is : Hello World I am
}

Function to get the Words from string:

private string FindFirstWords(string input, int HowManyFind)
{
string REGEX = @"([\w]+\s+){" + HowManyFind + "}";

StringBuilder output = new StringBuilder();

foreach (Capture capture in Regex.Match(input, REGEX).Captures)
{
output.Append(capture.Value);
}
return output.ToString();
}

3. foreach loop in Enum
==================================

objDataImport = new DataImport();
foreach (string s in Enum.GetNames(typeof(DataImport.eTotalFeature)))
{
objDataImport.CurrentFeature = (DataImport.eTotalFeature)Enum.Parse(typeof(DataImport.eTotalFeature), s);
objDataImport.FetchContent();
}

4. Read line by line from text file in C#
==========================================

string strFile = @"C:\Files\new.txt";

StreamReader objStreamReader = File.OpenText(strFile);

string strGetLine;
while ((strGetLine = objStreamReader.ReadLine()) != null)
{
Response.Write(strGetLine);
}

How to download any file with Asp.Net
=================================

string FileName = Server.MapPath("style.css").ToString();

Response.Clear();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment; filename=Name.css;");

byte[] buffer = System.IO.File.ReadAllBytes(FileName);

System.IO.MemoryStream mem = new System.IO.MemoryStream();
mem.Write(buffer, 0, buffer.Length);

mem.WriteTo(Response.OutputStream);
Response.End();


Render GridView to Html String
==========================

In many times I have faced a problem when you want to
render html string for GridView Control, but you
probably find error like...

"Control '' of type 'GridView' must be placed inside a form tag with runat=server."

In this case you have to use one method to avoid this error..

public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the
// specified ASP.NET server control at run time.

// No code required here.
}

and in the page directives just add this code marked in Bold Text..

Some reading before Interview

What are the OOPS concepts?

1) Encapsulation: It is the mechanism that binds together code and
data in manipulates, and keeps both safe from outside interference and
misuse. In short it isolates a particular code and data from all other
codes and data. A well-defined interface controls the access to that
particular code and data.

2) Inheritance: It is the process by which one object acquires the
properties of another object. This supports the hierarchical
classification. Without the use of hierarchies, each object would need
to define all its characteristics explicitly. However, by use of
inheritance, an object need only define those qualities that make it
unique within its class. It can inherit its general attributes from
its parent. A new sub-class inherits all of the attributes of all of
its ancestors.

3) Polymorphism: It is a feature that allows one interface to be used
for general class of actions. The specific action is determined by the
exact nature of the situation. In general polymorphism means "one
interface, multiple methods", This means that it is possible to design
a generic interface to a group of related activities. This helps
reduce complexity by allowing the same interface to be used to specify
a general class of action. It is the compiler's job to select the
specific action (that is, method) as it applies to each situation.

What is the difference between a Struct and a Class?

The struct type is suitable for representing lightweight objects such
as Point, Rectangle, and Color. Although it is possible to represent a
point as a class, a struct is more efficient in some scenarios. For
example, if you declare an array of 1000 Point objects, you will
allocate additional memory for referencing each object. In this case,
the struct is less expensive.
When you create a struct object using the new operator, it gets
created and the appropriate constructor is called. Unlike classes,
structs can be instantiated without using the new operator. If you do
not use new, the fields will remain unassigned and the object cannot
be used until all of the fields are initialized.
It is an error to declare a default (parameterless) constructor for a
struct. A default constructor is always provided to initialize the
struct members to their default values.
It is an error to initialize an instance field in a struct.
There is no inheritance for structs as there is for classes. A struct
cannot inherit from another struct or class, and it cannot be the base
of a class. Structs, however, inherit from the base class Object. A
struct can implement interfaces, and it does that exactly as classes
do.
A struct is a value type, while a class is a reference type.

Value type & reference types difference? Example from .NET. Integer
& struct are value types or reference types in .NET?

Most programming languages provide built-in data types, such as
integers and floating-point numbers, that are copied when they are
passed as arguments (that is, they are passed by value). In the .NET
Framework, these are called value types. The runtime supports two
kinds of value types:
Built-in value types
The .NET Framework defines built-in value types, such as System.Int32
and System.Boolean, which correspond and are identical to primitive
data types used by programming languages.
User-defined value types
Your language will provide ways to define your own value types, which
derive from System.ValueType. If you want to define a type
representing a value that is small, such as a complex number (using
two floating-point numbers), you might choose to define it as a value
type because you can pass the value type efficiently by value. If the
type you are defining would be more efficiently passed by reference,
you should define it as a class instead.
Variables of reference types, referred to as objects, store references
to the actual data. This following are the reference types:
class
interface
delegate
This following are the built-in reference types:
object
string


What is Method Overriding? How to override a function in C#?

Use the override modifier to modify a method, a property, an indexer,
or an event. An override method provides a new implementation of a
member inherited from a base class. The method overridden by an
override declaration is known as the overridden base method. The
overridden base method must have the same signature as the override
method.
You cannot override a non-virtual or static method. The overridden
base method must be virtual, abstract, or override.

Can we call a base class method without creating instance?

Its possible If its a static method.
Its possible by inheriting from that class also.
Its possible from derived classes using base keyword.


In which cases you use override and new base?

Use the new modifier to explicitly hide a member inherited from a base
class. To hide an inherited member, declare it in the derived class
using the same name, and modify it with the new modifier.


What are Sealed Classes in C#?

The sealed modifier is used to prevent derivation from a class. A
compile-time error occurs if a sealed class is specified as the base
class of another class. (A sealed class cannot also be an abstract
class)

UDDI
(Universal Description, Discovery and Integration)

WSDL
(Web Services Discription Language)

Web Service (Definition)

- The W3C defines a Web service[1] as a software system designed to support interoperable machine-to-machine interaction over a network.

- A Web Service is a software component that is described via WSDL and is capable of being accessed via standard network protocols such as but not limited to SOAP over HTTP.

SOAP (Definition)

- SOAP is a standard for exchanging XML-based messages over a computer network, normally using HTTP. SOAP forms the foundation layer of the web services stack, providing a basic messaging framework that more abstract layers can build on.

.Net code Compilation and Execution

* Source code is converted to Microsoft Intermediate Language and an assembly is created.
* Upon execution of a .NET assembly, its MSIL is passed through the Common Language Runtime's JIT compiler to generate native code. (NGEN compilation eliminates this step at run time.)
* The native code is executed by the computer's processor.

What is XML ?

- XML (Extensible Markup Language) is a W3C initiative that allows information and services to be encoded with meaningful structure and semantics that computers and humans can understand. XML is great for information exchange, and can easily be extended to include user-specified and industry-specified tags.
- XML is a markup language for documents containing structured information.

What is UML ?

UML is a general-purpose modeling language that includes a standardized graphical notation used to create an abstract model of a system.