Contents
Introduction
In this section we will touch base on one of important concepts in ASP.NET. You can download my .NET Interview Question PDF from http://www.questpond.com/SampleDotNetInterviewQuestionBook.zip .
You can download the software architecture interview questions PDF here: Download Software Architecture Interview Questions.
Previous parts of my interview questions series for architects:
UML interview questions: Part 1: SoftArch5.aspx
(B) What is the sequence in which ASP.NET events are processed?
Following is the sequence in which the events occur:
Page_Init
- Page load
- Control events
- Page unload event
Page_init
event only occurs when first time the page is started, but Page Load occurs in subsequent requests of the page.
(B) In which event are the controls fully loaded?
Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init
events but you will see that view state is not fully loaded during this event.
(B) How can we identify that the Page is postback?
The Page
object has an IsPostBack
property which can be checked to know if the page was posted back.
(B) How does ASP.NET maintain state in between subsequent requests?
Refer caching chapter.
(A) What is event bubbling?
Server controls like DataGrid
, DataList
, and Repeater
can have other child controls inside them. For example, DataGrid can have a combobox inside DataGrid. These child controls do not raise their events by themselves, rather they pass the event to the container parent (which can be a DataGrid
, DataList
, Repeater
), which are passed to the page as an ItemCommand
event. As the child control sends events to the parent it is termed as event bubbling.
(B) How do we assign page specific attributes?
Page attributes are specified using the @Page
directive.
(A) How do we ensure view state is not tampered?
Using the @Page
directive and setting the EnableViewStateMac
property to true
.
(B) What is the use of @Register directives?
@Register
directive informs the compiler of any custom server control added to the page.
(B) What is the use of the Smart Navigation property?
It’s a feature provided by ASP.NET to prevent flickering and redrawing when the page is posted back.
Note: This is only supported for the IE browser. Project with browser compatibility requirements have to think of other ways to avoid flickering.
(B) What is the AppSetting section in the Web.Config file?
The Web.config file defines the configuration for a web project. Using the AppSetting
section, we can define user-defined values. The example below defines the “Connection String” section which will be used throughout the project for the database connection.
<Configuration>
<appSettings>
<add key="ConnectionString" value="server=xyz;pwd=www;database=testing" />
</appSettings>
(B) Where is the ViewState information stored?
In the HTML hidden fields.
(I) What is the use of the @OutputCache directive in ASP.NET?
It is used for caching. See more in the Caching article.
(B) How can we create custom controls in ASP.NET?
User controls are created using .ASCX in ASP.NET. After the .ASCX file is created you need two things so that the ASCX can be used in the project:
<%@ Register tag prefix="Accounting" Tag name="footer" Src="Footer.ascx" %>
<Accounting: footer runat="server" />
- Register the ASCX control in the page using the
<%@ Register
directive. Example: - Now to use the above accounting footer in the page, you can use the below directive:
(B) How many types of validation controls are provided by ASP.NET?
There are six main types of validation controls:
RequiredFieldValidator
: It checks whether the control has any value. It is used when you want the control to not be empty. RangeValidator
: It checks if the value in the validated control is in that specific range. Example, TxtCustomerCode
should not be more than eight lengths. CompareValidator
: It checks that the value in the controls should match some specific value. Example, textbox TxtPie
should be equal to 3.14. RegularExpressionValidator
: When we want the control, the value should match with a specific regular expression. CustomValidator
: It is used to define User Defined validation. ValidationSummary
: It displays summary of all current validation errors on an ASP.NET page.
Note: It is rare that someone will ask step by step about all the validation controls. Rather they will ask for what type of validation a validator will be used. For example in one of the interviews I was asked how to display the summary of all errors in a validation control... just uttered one word: ValidationSummary
.
(B) Can you explain AutoPostBack?
If we want the control to automatically post back in case of an event, we will need to check this attribute as true
. For example, on a ComboBox change, we need to send the event immediately to the server side then set the AutoPostBack
attribute to true
.
(B) How can you enable automatic paging in DataGrid?
Following are the things to be done in order to enable paging in DataGrid:
- Set
AllowPaging
to true. - In the
PageIndexChanged
event set the current page index clicked.
Note: The answers are very short, if you have implemented them practically it is just a revision. If you are a fresher, just make a sample code using a DataGrid and try to implement this functionality.
(B) What is the use of the GLOBAL.ASAX file?
It allows to execute ASP.NET application level events and set application-level variables.
(B) What is the difference between Web.config and Machine.Config?
Web.config files apply settings to each web application, while Machine.config file apply settings to all ASP.NET applications.
(B) What is a SESSION and APPLICATION object?
The Session object stores information between HTTP requests for a particular user, while the Application object is global across users.
For further reading do watch the below interview preparation videos and step by step video series.