ASP.NET is the next version of ASP which provides the easiest way to build, deploy & run the web application on any browser. ASP.NET is based upon the event-driven and server-side programming model. This article contains the top 20 ASP.NET interview questions and answers, in order to prepare you for the interview.
What is ASP.NET?
ASP.NET Framework is a part of the .NET framework used to create a dynamic website, web application and web services. It is a server-side technology that uses all .NET compatible language such as C#, VB.NET, J# etc. which are compiled to Microsoft Intermediate Language (MSIL). ASP.NET uses server control to develop a rapid and interactive application in an easy way.
Features of ASP.NET:
It uses C# and VB.NET languages to build the website.
It allows us to separate HTML layout with server-side code.
It allows us to make the same class name qualifying under a different namespace.
ASP.NET pages are compiled, not interpreted.
ASP.NET is a request processing engine. It takes an incoming request and passes it through its internal pipeline to an endpoint where a developer can attach code to process that request.
What is the difference between Web Site and Web Application?
There are following differences between these two :
In a website, you cannot add multiple projects.
There is no project file (.csproj or .vbproj). All the files in a folder structure are automatically included in the site.
By default, compilation produces multiple assemblies.
The website is easy to create and deploy.
You can use different .NET languages on a single web site such as VB.NET pages and C# pages can be used on a single website.
You can edit a single page/file after deployment recompilation is not required.
Choose a website when one developer will responsible for creating and managing an entire website. Since decoupling is not possible on the website.
You cannot establish dependencies on the website.
In a web application, you can add multiple projects.
It has a Visual Studio project file (.csproj or .vbproj) stores information about the project like as the list of files that are included in the project, and any project-to-project references.
By default, compilation of code files (excluding .aspx and .ascx files) produces a single assembly.
It is easy to develop compared to the website.
You cannot use different .NET languages in a Web Application such as C# and VB.NET both cannot be used in a web application.
You cannot edit a single file. Recompilation is required.
The right choice for enterprise environments where multiple developers work for creating, testing and deployment. Different groups work on various components independently like one group work on the domain layer, other work on the UI layer hence, decoupling is possible here
You can establish dependencies in a Web Application.
What is a round trip?
The trip of a Web page from the client to the server and then back to the client is known as a round trip. In ASP.NET Response.Redirect() causes a round trip.
What is a Global.asax file?
The Global.asax file has been derived from the HttpApplication class. The Global.asax file is used to add application-level logic and processing. It does neither handles any UI related processing, nor it does support individual requests. It basically controls the following events.
Following are the important aspect of the use of the Global.asax file.
The code in the Global.asax is compiled when the web application is built for the first time.
Session level code and variables can be declared in Application_Start event.
Application level events are for the entire application and may be used for any user.
Session level events are user specific for the length of a session.
What is the difference between Web.config and Machine.config file?
Both files are used to define configurations for your ASP.NET application. There are following differences between these two configuration files.
The Web.config is used to define application-level settings.
If any setting is not specified in Web.config it inherits from Machine.config by default.
Web.config is an XML-based configuration file for an ASP.NET application which includes the setting for Data Connection, Customizing Security, State Management, Memory Management, Error Handling and much more.
It sometimes called application and session level configuration file.
You can have more than one Web.config files in your ASP.NET application.
This file is at the highest level in the configuration hierarchy.
You can find it at <WinDir>\Microsoft.NET\Framework\<version>\config\machine.config
Machine.config is used for defining server level setting.
It defines the supported configuration file section and ASP.NET work process.
It registers providers that can be used for advanced features such as profiles membership and role-based security.
It is automatically installed while installing Visual Studio.NET.
It sometimes called machine level configuration file.
Only one Machine.config file can be at the machine level.
How to define a connection string in Web.config file?
Following is the way to define a connection string in Web.config for SQL Server database.
<connectionStrings> <add name="strcon" connectionString="Data Source=DonetApp; Initial Catalog=dotnetDB; Persist Security Info=True; User ID=asif@123; Password=123@asif" providerName="System.Data.SqlClient"/> </connectionStrings>
What are various page events in ASP.NET?
Following are the page level events in ASP.NET.
PreInit: This is the first event of a page used to set values such as a master page.
Init: This event fires after each control have been initialized. You can use this event to change the initialized value of controls.
InitComplete: This event is raised after all initializations of a page and its controls have been completed.
PreLoad: This event fires before view state has been loaded for a page and its controls and before page postback processing. This event is useful when you need to write code after the page is initialized.
Load(PageLoad): Page load event is generally used to check postback and then sets control properties appropriately. After this event, the load event of child control is called.
ControlEvents(Postback): This event is called when a page or its controls causes postback such as ButtonClick event, SelectedIndexChanged event, CheckedChanged events etc.
LoadComplete: At this event, all controls are loaded even after additional processing can be done here.
PreRender: This event is taking place before view state is saved also it allows final changes to the page or its control.
SaveStateComplete: Any changes to the page’s controls at this point are ignored here. This event is useful if you need to write processing that requires the view state to be set.
Render: In real it is not an event this is actually a method of a page object and its controls. At this point, controls are rendered in client-side HTML, DHTML, and scripts for the browser.
Unload: This event is used to clean up code you can use it to manually release resources.
What are server controls in ASP.NET?
The ASP.NET server controls are objects on the ASP.NET pages that run when the Web page is requested. Many server controls, such as button and text box, are similar to the HTML controls. In addition to the HTML controls, there are many controls, which include complex behaviour, such as the controls used to connect to data sources and display data.
What is the difference between Hyperlink and LinkButton?
A Hyperlink control does not have the Click and Command events; whereas the LinkButton control has these events, which can be handled in the code-behind file of the Web page.
What are navigation controls?
Navigation controls help us to navigate in a Web application easily. These controls store all the links in a hierarchical or drop-down structure; thereby facilitating easy navigation in a Web application.
How many navigation controls are in ASP.NET?
There are three navigation controls in ASP.NET.
What is the difference between client-side and server-side validations?
What is the difference between User Control and Custom Control?
The differences between User Control and Custom Control are given below-User ControlCustom ControlBuilt into .ascx file.Built into a redistributable assembly (i.e. a DLL).Generally used for static content.Generally used for dynamic content.It is easy to create and use as it inherits from server controls.Comparatively difficult because you have to develop from scratch.Can be only used with current applications.Can be used with any number of applications.Language dependent.Language independent, a control created in C# can be used in VB.NET.Cannot be added to Visual Studio toolbox.Can be added to Visual Studio toolbox.
What are Globalization and Localization?
Globalization is the process of designing and developing an application that functions for multiple cultures or locales. In other words, Globalization is the process of designing and developing an application in such a way that it can be used by users of multiple cultures. Globalization makes your application ready for international markets. This process involves:
Identifying the culture and locale that must be supported by the application.
Designing features to support those cultures and locales.
Writing code that functions equally well with all the supported cultures and locales.
Localization is the process of customizing your application for a given culture or locale. In other words, Localization is the process of customizing your application in such a way that it behaves as per current culture or locale. Typically, Localization translates your application UI into current culture or locale.
What is a Resource File?
ASP.NET provides resource files to implement globalization and localization. The resource file is an XML file having extension resx. Each resource in the resx file is in the form of a key-value pair. For each culture which your application needs to support create a separate resource file. For example, WebResources.en.resx is a resource file for English language and WebResources.hi.resx is a resource file for the Hindi language.
What are Local Resources and Global Resources?
There are two types of resource files as given below :
Local Resources: Local resources are specific to a single web page and used for providing versions of a web page in different languages. These are stored in App_LocalResources folder.
Global Resources: Global resources are common for the whole web application and can be accessed by all the web pages. These are stored in the App_GlobalResources folder.
What is Neutral Culture, Culture, and Language?
A neutral culture is a culture that is associated with a language but not with a country or region. For example, "en" for English and in for Hindi. Culture consists of language and the country or region. It is denoted by culture code which contains two lowercase letters denoting the language and two uppercase letters denoting the country or region like as en-US for English in the US, en-GB for UK etc. A language is any spoken language like English (en), Hindi (hi), and German (de) etc.
What are the differences between GridView and DataGrid?
The differences between GridView and DataGrid are given below :GridViewDataGridIt was introduced with ASP.NET 2.0It was introduced with ASP.NET 1.0Built-in supports for Paging and Sorting.For sorting, you need to handle SortCommand event and rebind grid required and for paging, you need to handle the PageIndexChanged event and rebind grid requiredBuilt-in supports for Update and Delete operations.Need to write code for implementing Update and Delete operations.Supports auto format or style features.This feature is not supported.Performance is slow as compared to DataGridPerformance is fast as compared to GridView.
What are the differences between ListView and Repeater?
The differences between ListView and Repeater are given below :ListViewRepeaterIt was introduced with ASP.NET 3.5It was introduced with ASP.NET 1.0Built-in supports for paging and sorting.Need to write custom code.Built-in supports for Data grouping.Need to write custom code.Built-in supports for insert update and delete operation.Need to write custom code.Performance is slow as compared to RepeaterPerformance is fast as compared to ListView
What are the different modes for the Session state in ASP.NET?
There are following the different mode of session state which can be defined in a Web.config file.
Off: Specify that Session state is not enabled.
InProc: This is the default mode of the session. In this mode session state is stored on the web server i.e. IIS where an application is running.
OutProc: The OutProc mode can be handled by using the following ways -
State Server: In this mode, the session is stored in a separate process called ASP.NET state service. This ensures that the session state will be available if the web application is restarted. This way also makes the session state availability to multiple web servers in a web farm.
SQL Server: In this mode, the session is stored in a SQL Server database. This also ensures that the session state will be available if the web application is restarted. This way also makes the session state availability to multiple web servers in a web farm.
Note: Session_End event of Global.asax is fired only in InProc session mode. The object stored in Session state must be serializable if the session mode is set to OutProc.
I hope these questions and answers will help you to crack your ASP.NET interview. These interview Questions have been taken from our new released eBook ASP.NET/AJAX Interview Questions & Answers. This book contains more than 110+ ASP.NET/AJAX interview questions.
This eBook has been written to make you confident in WCF with a solid foundation. Also, this will help you to turn your programming into your profession. It's would be equally helpful in your real projects or to crack your ASP.NET Interview.