Showing posts with label ASP.NET Interview Questions. Show all posts
Showing posts with label ASP.NET Interview Questions. Show all posts

Monday, 9 December 2013

Difference Between Repeater and DataList and GridView

Repeater and DataList and GridView are Data-bound controls that bound to a data source control like SqlDataSource, LinqDataSource to display and modify data in your Asp.Net web application. Data-bound controls are composite controls that contains others Asp.Net controls like as Label, TextBox, DropdownList etc. into a single layout. In this article, I am going to expose the difference among these three.

Difference between DataList and Repeater

DataList
Repeater
Rendered as Table.
Template driven.
Automatically generates columns from the data source.
This features is not supported.
Selection of row is supported.
Selection of row is not supported.
Editing of contents is supported.
Editing of contents is not supported.
You can arrange data items horizontally or vertically in DataList by using property RepeatDirection.
This features is not supported.
Performance is slow as compared to Repeater
This is very light weight and fast data control among all the data control.

Difference between GridView and Repeater

GridView
Repeater
It was introduced with Asp.Net 2.0.
It was introduced with Asp.Net 1.0.
Rendered as Table.
Template driven.
Automatically generates columns from the data source.
This features is not supported.
Selection of row is supported.
Selection of row is not supported.
Editing of contents is supported.
Editing of contents is not supported.
Built-in Paging and Sorting is provided.
You need to write custom code.
Supports auto format or style features.
This has no this features.
Performance is very slow as compared to Repeater.
This is very light weight and fast data control among all the data control.

Difference between GridView and DataList

GridView
DataList
It was introduced with Asp.Net 2.0.
It was introduced with Asp.Net 1.0.
Built-in Paging and Sorting is provided.
You need to write custom code.
Built-in supports for Update and Delete operations.
Need to write code for implementing Update and Delete operations.
Supports auto format or style features.
This features is not supported.
RepeatDirection property is not supported.
You can arrange data items horizontally or vertically in DataList by using property RepeatDirection.
Doesn’t support customizable row separator.
Supports customizable row separator by using SeparatorTemplate.
Performance is slow as compared to DataList.
Performance is fast is compared to GridView.

Wednesday, 4 December 2013

What is an assembly?


Answer:
PreCompiled code that can be executed by the .NET runtime environment. It can be an .exe or .dll



What are different kind of assemblies? What is satellite assembly and public assembly?
Answer:
There are three types of assemblies:
a.Public Assembly:dll which can be used by multiple applications at a time. It is generally stored in GAC(Global Assembly Cache). 
b.Private Assembly:It is used by only one application and generally stored in the Application specific folder.
c.Satellite Assembly:A Satellite Assembly contains only static objects such as images and other non-executable files such as resource-only files that are required by the application.

What are difference Session Management Techniques in ASP.NET

Answer:
Sessions,Cookies,QueryString,ViewState,Application objects,Hidden Fields.

Tuesday, 3 December 2013

What is http Module?

When an application runs in a web-server,HTTPModules are found before and after the HTTPHandlers.These are used if we want to add some extra functionality to the existing code or add some new functionality.

Saturday, 30 November 2013

ASP.NET Interview Questions on DataSet


What is a DataSet?
DataSet is an in-memory cache of data.

In which namespace is the DataSet class present? 
System.Data

Can you add more than one table to a dataset?
Yes

Can you enforce constarints and relations on tables inside a DataSet?
Yes, the DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects.

What happens when you invoke AcceptChanges() method on a DataSet? 
Invoking AcceptChanges() method on the DataSet causes AcceptChanges() method to be called on each table within the DataSet.

Both the DataRow and DataTable classes also have AcceptChanges() methods. Calling AcceptChanges() at the DataTable level causes the AcceptChanges method for each DataRow to be called.

When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode end their edits successfully. The RowState property of each DataRow also changes. Added and Modified rows become Unchanged, and Deleted rows are removed.

If the DataSet contains ForeignKeyConstraint objects, invoking the AcceptChanges method also causes the AcceptRejectRule to be enforced.

Is there a way to clear all the rows from all the tables in a DataSet at once?
Yes, use the DataSet.Clear() method to clear all the rows from all the tables in a DataSet at once.


What is the difference between DataSet.Copy() and DataSet.Clone()? 
DataSet.Clone() copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.

DataSet.Copy() copies both the structure and data.

How do you get a copy of the DataSet containing all changes made to it since it was last loaded? 
Use DataSet.GetChanges() method

What is the use of DataSet.HasChanges() Method? 
DataSet.HasChanges method returns a boolean true if there are any changes made to the DataSet, including new, deleted, or modified rows. This method can be used to update a DataSource only if there are any changes.

How do you roll back all the changes made to a DataSet since it was created? 
Invoke the DataSet.RejectChanges() method to undo or roll back all the changes made to a DataSet since it was created.

What happnes when you invoke RejectChanges method, on a DataSet that contains 3 tables in it? 
RejectChanges() method will be automatically invoked on all the 3 tables in the dataset and any changes that were done will be rolled back for all the 3 tables.

When the DataTable.RejectChanges method is called, any rows that are still in edit-mode cancel their edits. New rows are removed. Modified and deleted rows return back to their original state. The DataRowState for all the modified and deleted rows will be flipped back to unchanged.

What is the DataSet.CaseSensitive property used for? 
When you set the CaseSensitive property of a DataSet to true, string comparisons for all the DataTables within dataset will be case sensitive. By default the CaseSensitive property is false.

What are the advantages and disadvantages of a layered architecture


The following are the advantages of a layered architecture:

Layered architecture increases flexibility, maintainability, and scalability. In a Layered architecture we separate the user interface from the business logic, and the business logic from the data access logic. Separation of concerns among these logical layers and components is easily achieved with the help of layered 

architecture.

Multiple applications can reuse the components. For example if we want a windows user interface rather than a web browser interface, this can be done in an easy and fast way by just replacing the UI component. All the other components like business logic, data access and the database remains the same. Layered architecture allows to swap and reuse components at will.

Layered architecture enables teams to work on different parts of the application parallely with minimal dependencies on other teams.

Layered architecture enables develop loosely coupled systems.

Different components of the application can be independently deployed, maintained, and updated, on different time schedules.

Layered architecture also makes it possible to configure different levels of security to different components deployed on different boxes. sO Layered architecture, enables you to secure portions of the application behind the firewall and make other components accessible from the Internet.

Layered architecture also helps you to test the components independently of each other.

The following are the disadvantages of a layered architecture:                 

There might be a negative impact on the performance as we have the extra overhead of passing through layers instead of calling a component directly. 

Development of user-intensive applications can sometime take longer if the layering prevents the use of user interface components that directly interact with the database.

The use of layers helps to control and encapsulate the complexity of large applications, but adds complexity to simple applications.

Changes to lower level interfaces tend to percolate to higher levels, especially if the relaxed layered approach is used.

What is the difference between layers and tiers


Layers refer to logical seperation of code. Logical layers help you organise your code better. For example an application can have the following layers.


1)Presentation Layer or UI Layer
2)Business Layer or Business Logic Layer
3)Data Access Layer or Data Layer


The aboove three layers reside in their own projects, may be 3 projects or even more. When we compile the projects we get the respective layer DLL. So we have 3 DLL's now.


Depending upon how we deploy our application, we may have 1 to 3 tiers. As we now have 3 DLL's, if we deploy all the DLL's on the same machine, then we have only 1 physical tier but 3 logical layers.


If we choose to deploy each DLL on a seperate machine, then we have 3 tiers and 3 layers.


So, Layers are a logical separation and Tiers are a physical separation. We can also say that, tiers are the physical deployment of layers.


Tiers:
1) Presenation Tier or UI Tier (Hosts the Presentation Layer or UI Layer). This can be considered as web server in case of an ASP.NET web application. 
2) Application Tier or Business Tier (Hosts Business Layer or Business Logic Layer). 
3) Data Access Tier or Data Tier (Hosts Data Access Layer or Data Layer).
4) Database Tier - SQL Server or Oracle (or any other database) which has tables, stored procedures and other database objects.


In general the following are the responsibilities of each layer or tier:


1)Presentation Layer or Tier is usually responsible for interacting with the user.
2)Business Layer or Tier is responsible for implementing the business logic of the application.
3)Data Access Layer or Tier is responsible for encapsulating the code that accesses the persistent data stores such as a relational database.

What is the process for strong naming an assembly


What is the process for strong naming an assembly ?
or
What is the purpose of strong naming tool ( sn.exe ) in .NET ?

In .NET, the assembly name usually consists of 4 parts as listed below.
1. Simple Textual Name
2. Version Number (The version number is also divided into 4 parts)
3. Culture
4. Public Key Token 

If an assembly contains, all the 4 parts, then the assembly is a strongly named assembly, other wise the assembly is called as a weak named assembly. In general, when you compile any .NET application, the generated assembly by default will have the Simple Textual Name, Version Number and Culture but not the public key token. If you have to sign the assembly with a public key token, you first have to generate the key pair using key generation tool called strong naming tool (sn.exe). The generated key pair will consist of a private and a public key and are written into a key file. Key files have the extension of .snk

We now have to associate the key file with the project, so that when we compile the project, the generated assembly is signed using the key pair. To do this, In AssemblyInfo.cs file of the project, specifyAssemblyKeyFile attribute as shown below.
              [assembly: AssemblyKeyFile("MyKey.snk")]

The last and final step is to build the project which will automatically sign the assembly using the key file. This process generates the strongly named assembly.


In short, there are 3 simple steps to generate a strongly named assembly.
1. Generate the key pair using strong naming tool, SN.exe.

2. Associate the generated Key file to the project using AssemblyKeyFile, which is present in AssemblyInfo.cs file.

3. Build the project.

Once, you have strongly named the assembly, you can copy it to GAC. There are 2 ways to copy an assembly into GAC.
1. Using simple drag and drop : Drag the generated assembly into the GAC folder. Usually the path for GAC is c:\windows\assembly. On some machines this could be c:\winnt\assembly.

2. Use GAC utility : Use GAC Utility tool(gacutil.exe) as shown below in visual studio command prompt. 
               gacutil.exe -i C:\MyAssembly.dll (- i stands for install)

Once, you have successfuly copied the assembly into GAC, notice the four parts of the assembly name. Theculture column could be empty, indicating that the assembly is language neutral. 

Please click here to read few other follow up interview questions related to strong named assemblies.

If you can improve this answer further, please feel free to do so by submitting the form below. Thank you very much for your contribution.

ASP.NET Page is very slow. What will you do to make it fast


This is a very common asp.net interview question asked in many interviews. There are several reasons for the page being slow. We need to identify the cause. 

1. Find out which is slow, is it the application or the database : If the page is executing SQL queries or stored procedures, run those on the database and check how long do they take to run. If the queries are taking most of the time, then you know you have to tune the queries for better performance. To tune the queries, there are several ways and I have listed some of them below.
   a) Check if there are indexes to help the query
   b) Select only the required columns, avoid Select *.
   c) Check if there is a possiblity to reduce the number of joins
   d) If possible use NO LOCK on your select statements
   e) Check if there are cursors and if you can replace them with joins

2. If the queries are running fast, then we know it is the application code that is causing the slowness. Isolate the page event that is causing the issue by turning tracing on. To turn tracing on, set Trace="true" in the page directive. Once you have tracing turned on you should see trace information at the bottom of the page as shown in the image below. In this case Page Load event is taking the maximum time. So we know, the code inPage_Load event is causing the issue. Once you look at the code, you should be able to nail down the issue.