.NET Interview Questions – Part 7

1.Can you explain what inheritance is and an example of when you might use it?

Inheritance is a fundamental feature of an object oriented system and it is simply the ability to inherit data and functionality from aparent object. Rather than developing new objects from scratch, new code can be based on the work of other programmers, adding only new features that are needed.

2.How would you implement inheritance using VB.NET/C#?

When we set out to implement a class using inheritance, we must first start with an existing class from which we will derive our new subclass. This existing class, or base class, may be part of the .NET system class library framework, it may be part of some other application or .NET assembly, or we may create it as part of our existing application. Once we have a base

3.Whats an assembly?

Assembliesare the building blocks of .NET Frameworkapplications:
They form the fundamental unit of deployment, version control, reuse,activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality.An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.

4.Describe the differencebetween inline and code behind which is best in a loosely coupled solution?

ASP.NET supports two modes of page development: Page logic code that is written inside <script runat=server> blocks within an .aspx file and dynamically compiled the first time the page is requested on the server. Page logic code that is written within an external class that is compiled prior to deployment on a server and linked “behind” the .aspx file at run time.

5.Explain what a diffgram is, and a good use for one?

A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order.

6.Where would you use an iHTTPModule, and what are the limitations of anyapproach you might take in implementing one?

One of ASP.NET’s most useful features is the extensibility of the HTTP pipeline, the path that data takes between client and server. You can use them to extend your ASP.NET applications by adding pre and post
processing to each HTTP request coming into your application. For example, if you wanted custom authentication facilities for your application, the best technique would be to intercept the request when it comes in and process the request in a custom HTTP module.

7.In what order do the events of an ASPX page execute. As a developer is it important to undertsand these events?

Every Page object (which your .aspx page is) has nine events, most of which you will not have to worry about in your day to day dealings with ASP.NET. The three that you will deal with the most are: Page_Init, Page_Load,Page_PreRender.

8.Which method do you invoke on the DataAdapter control to load your generated dataset with data?

If my DataAdapter is sqlDataAdapter and my DataSet is dsUsers then it is called this way:

9.Which template must you provide, in order to display data in a Repeater control?


10.How can you provide an alternating color scheme in a Repeater control?

AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other row (alternating items) in the Repeater control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties.

11.What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?

You must set the DataMember property which Gets or sets the specific table in the DataSource to bind to the control and the DataBind method to bind data from a source to a server control. This method is commonly used after retrieving a data set through adatabase query.

12.What base class do all Web Forms inherit from?


13.What method do you use to explicitly kill a user’s session?

The Abandon method destroys all the objects stored in a Session object and releases their resources.If you do not call the Abandon method explicitly, the server destroys these objects when
the session times out.

14.How do you turn off cookies for one page in your site?

Use the Cookie.Discard Property which Gets or sets the discard flag set by the server.When true, this property instructs the client application not to save the Cookie on the user’s hard disk when a session ends.

15.Which two properties are on every validation control?

ControlToValidate &ErrorMessage properties

16.How do you create a permanent cookie?

Setting the Expires property to MinValue means that the Cookie never expires.

17.Which method do you use to redirect the user to another page without performing around trip to the client?


18.What is the transport protocol you use to call a Web service?

SOAP. Transport Protocols: It is essential for the acceptance of Web Services that they are based on established Internet infrastructure. This in fact imposes the usage of of the HTTP, SMTP and FTP protocols based on the TCP/IP family of transports. Messaging Protocol: The format of messages exchanged between Web Services clients and Web Services should be vendor neutral and should not carry details about the technology used to implement the service. Also, the message format should allow for extensions and different bindings to specific transport protocols. SOAP and ebXML Transport are specifications which
fulfill these requirements. We expect that the W3C XML Protocol Working Group defines a successor standard.

19.What does WSDL stand for?

Web Services Description Language

20.How does VB.NET/C# achieve polymorphism?

By using Abstract classes/functions.

21.What tags do you need to add within the asp:datagrid tags to bind columns manually?

Column tag and an ASP:databound tag.

22.How is a property designated as readonly?
In VB.NET:Public ReadOnly Property PropertyName As ReturnType Get ‘Your Property Implementation goes in here End Get End Property in C#
public returntype PropertyName
//property implementation goes here
// Do not write the set impl

23.Which control would you use if you needed to make sure the values in two different controls matched?
Use the CompareValidator control to compare the values of 2 different controls.

24.True or False: To test a Web service you must create a windows application or Web application to consume this service?


25. How many classes can a single .NET DLL contain?


26. Write three common properties of all validation controls.

Three common properties of validation controls are as follows:
ControlToValidate – Provides a control to validate
ErrorMessage – Displays an error message
IsValid – Specifies if the control’s validation has succeeded or not
Text – Displays a text for validation control before validation

27. What are navigation controls? How many navigation controls are there in ASP.NET 4.0?

Navigation controls help you 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.
There are three navigation controls in ASP.Net 4.0.

28. What happens if an ASP.NET server control with event-handling routines is missing from its definition?

The compilation of the application fails.

29. What are server-side comments?

Server-side comments are included in an ASP.NET page for the purpose of documentations as shown in the following code snippet:

<%–This is an example of server-side comments –%>

The server-side comments begin with <%– and end with –%>.

30. How can we provide the WebParts control functionality to a server control?

We can provide the WebParts controls functionality to a server control by setting the CreateWebPart property of WebPartManger.

31. How do you prevent a validation control from validating data at the client end?

You can prohibit a validation control to validate data at the client side by setting the EnableClientScript property to False.

32. What is cross-page posting in ASP.NET?

The Server.Transfer() method is used to post data from one page to another. In this case, the URL remains the same. However, in cross page posting, data is collected from different Web pages and is displayed on a single page. To do so, you need to set the PostBackUrl property of the control, which specifies the target page. In the target page, you can access the PreviousPage property. For this, you need to use the @PreviousPageType directive. You can access the controls of previous page by using the FindControl() method.

33. Which ASP.NET configuration options are supported in the ASP.NET implementation on the shared Web hosting platform?

There are many ASP.NET configuration choices, which are not able to configure at the site, application, or child directory level on the shared hosting environment. Some options can produce security, performance, and stability problem to the server and therefore cannot be changed.
The following settings are the only ones that can be changed in the web.config file(s) of your Web site:

34. Explain the Application and Session objects in ASP.NET.

Application state is used to store data corresponding to all the variables of an ASP.NET Web application. The data in an application state is stored once and read several times. Application state uses the HttpApplicationState class to store and share the data throughout the application. You can access the information stored in an application state by using the HttpApplication class property. Data stored in the application state is accessible to all the pages of the application and is the same for all the users accessing the application. The HttpApplicationState class provides a lock method, which you can use to ensure that only one user is able to access and modify the data of an application at any instant of time.Each client accessing a Web application maintains a distinct session with the Web server, and there is also some specific information associated with each of these sessions. Session state is defined in the <sessionState> element of the web.config file. It also stores the data specific to a user session in session variables. Different session variables are created for each user session. In addition, session variables can be accessed from any page of the application. When a user accesses a page, a session ID for the user is created. The session ID is transferred between the server and the client over the HTTP protocol using cookies.

35. How will you differentiate a submaster page from a top-level master page?

Similar to a content page, a submaster page also does not have complete HTML source code; whereas, a top-level master page has complete HTML source code inside its source file.

36. What are Web server controls in ASP.NET?

The ASP.NET Web server controls are objects on the ASP.NET pages that run when the Web page is requested. Many Web 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 behavior, such as the controls used to connect to data sources and display data.

37. What is the difference between a HyperLink control and a LinkButton control?

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.

38. What are the various ways of authentication techniques in ASP.NET?

There are various techniques in ASP.NET to authenticate a user. You can use one of the following ways of authentication to select a built-in authentication provider:
Windows Authentication – This mode works as the default authentication technique. It can work with any form of Microsoft Internet Information Services (IIS) authentication, such as Basic, Integrated Windows authentication (NTLM/Kerberos), Digest, and certificates. The syntax of Windows authentication mode is given as follows: <authentication mode=”windows” /> Forms Authentication – You can specify this mode as a default authentication mode by using the following code snippet: <authentication mode=”Forms”/>
Passport – This mode works with Microsoft Passport authentication, as shown in the following code snippet: <authentication mode = “Passport”/>

39. What are the different ways to send data across pages in ASP.NET?

The following two ways are used to send data across pages in ASP.NET:
Public properties

40. What does the WebpartListUserControlPath property of a DeclarativeCatalogPart control do?

The WebpartListUserControlPath property sets the route of the user defined control to a DeclarativeCatalogPart control.

41. What do you mean by the Web Part controls in ASP.NET?

The Web Part controls are the integrated controls, which are used to create a Web site. These controls allow the users to change the content, outlook, and state of Web pages in a Web browser.

42. What type of the CatalogPart control enables users to restore the Web Parts that have been removed earlier by the user?

The PageCatalogPart control.

43. What is the use of web.config? What is the difference between machine.config and web.config?

ASP.NET configuration files are XML-based text files for application-level settings and are saved with the name web.config. These files are present in multiple directories on an ASP.NET Web application server. The web.config file sets the configuration settings to the directory it is placed in and to all the virtual sub folders under it. The settings in sub directories can optionally override or change the settings specified in the base directory.

The difference between the web.config and machine.config files is given as follows:
<WinDir>Microsoft.NETFramework<version>configmachine.config provides default configuration settings for the entire machine. ASP.NET configures IIS to prohibit the browser directly from accessing the web.config files to make sure that their values cannot be public. Attempts to access those files cause ASP.NET to return the 403: Access Forbidden error.ASP.NET uses these web.config configuration files at runtime to compute hierarchically a sole collection of settings for every URL target request. These settings compute only once and cached across further requests. ASP.NET automatically checks for changing file settings and do not validate the cache if any of the configuration changes made.

44. Explain the concept of states in ASP.NET.

State is quite an innovative concept in Web development because it eliminates the drawback of losing state data due to reloading of a Web page. By using states in a Web application, you can preserve the state of the application either at the server or client end. The state of a Web application helps you to store the runtime changes that have been made to the Web application. For example, as already described earlier, a change in the data source of the Web application might be initiated by a user when he/she selects and saves some products in the shopping cart.
If you are not using states, these changes are discarded and are not saved. You may think that the whole concept of storing states is optional. However, under certain circumstances, using states with applications is imperative. For example, it is necessary to store states for Web applications, such as an e-commerce shopping site or an Intranet site of a company, to keep track of the requests of the users for the items they have selected on the shopping site or the days requested for vacation on the Intranet site.

45. Can we validate a DropDownList by RequiredFieldValidator?

Yes, we can validate a DropDownList by RequiredFieldValidator. To perform this validation, we have to set the InitialValue property of RequiredFieldValidator control.

46. List the features of the Chart control.

The following are the features of the Chart control:
Bounds a chart with any data source.
Simple manipulation of chart data, such as copying, merging, grouping, sorting, searching, and filtering.
Support many statistical and financial formulas for data analysis.
Provide advanced chart outlook, such as 2-D, 3-D, lighting, and perspective.
Support events and customizations.
Includes interactivity with Microsoft AJAX.
Supports AJAX Content Delivery Network (CDN).

47. What’s the use of Response.Output.Write()?

We can write formatted output  using Response.Output.Write().

48. In which event of page cycle is the ViewState available?

After the Init() and before the Page_Load().

49. What is the difference between Server.Transfer and Response.Redirect?

In Server.Transfer page processing transfers from one page to the other 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.  The clients url history list or current url Server does not update in case of Server.Transfer.Response.Redirect is used to redirect the user’s browser to another page or site.  It performs 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.

50. From which base class all Web Forms are inherited?

Page class.

51. What are the different validators in ASP.NET?
Required field Validator
Range  Validator
Compare Validator
Custom Validator
Regular expression Validator
Summary Validator

52. Which validator control you use if you need to make sure the values in two different controls matched?

Compare Validator control.

53. What is ViewState?

ViewState is used to retain the state of server-side objects between page post backs.

54. Where the viewstate is stored after the page postback?

ViewState is stored in a hidden field on the page at client side.  ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.

55. How long the items in ViewState exists?

They exist for the life of the current page.

56. What are the different Session state management options available in ASP.NET?
ASP .net Interview Questions


In-Process stores the session in memory on the web server.
Out-of-Process Session state management stores data in an external server.  The external server may be either a SQL Server or a State Server.  All objects stored in session are required to be serializable for Out-of-Process state management.

57. How you can add an event handler?

Using the Attributes property of server side control.


58. What is caching?

Caching is a technique used to increase performance by keeping frequently accessed data or files in memory. The request for a cached file/data will be accessed from cache instead of actual location of that file.

59. What are the different types of caching?
ASP.NET has 3 kinds of caching :
Output Caching,
Fragment Caching,
Data Caching.

60. Which type if caching will be used if we want to cache the portion of a page instead of whole page?

Fragment Caching: It caches the portion of the page generated by the request. For that, we can create user controls with the below code:

<%@ OutputCache Duration=”120″ VaryByParam=”CategoryID;SelectedID”%>

61. List the events in page life cycle.

1) Page_PreInit
2) Page_Init
3) Page_InitComplete
4) Page_PreLoad
5) Page_Load
6) Page_LoadComplete
7) Page_PreRender

62. Can we have a web application running without web.Config file?


63. Is it possible to create web application with both webforms and mvc?

Yes. We have to include below mvc assembly references in the web forms application to create hybrid application.




64. Can we add code files of different languages in App_Code folder?

No. The code files must be in same language to be kept in App_code folder.

65. What is Protected Configuration?

It is a feature used to secure connection string information.

66. Write code to send e-mail from an ASP.NET application?

MailMessage mailMess = new MailMessage ();
mailMess.From = “[email protected]”;
mailMess.To = “[email protected]”;
mailMess.Subject = “Test email”;
mailMess.Body = “Hi This is a test mail.”;
SmtpMail.SmtpServer = “localhost”;
SmtpMail.Send (mailMess);

MailMessage and SmtpMail are classes defined System.Web.Mail namespace.

67. How can we prevent browser from caching an ASPX page?

We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:
Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());

68. What is the good practice to implement validations in aspx page?

Client-side validation is the best way to validate data of a web page. It reduces the network traffic and saves server resources.

69. What are the event handlers that we can have in Global.asax file?

Application Events: Application_Start , Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed,  Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache

Session Events: Session_Start,Session_End

70. Which protocol is used to call a Web service?

HTTP Protocol

71. Can we have multiple web config files for an asp.net application?

72. What is the difference between web config and machine config?

Web config file is specific to a web application where as machine config is specific to a machine or server. There can be multiple web config files into an application where as we can have only one machine config file on a server.

73.  Explain role based security ?

Role Based Security used to implement security based on roles assigned to user groups in the organization.

Then we can allow or deny users based on their role in the organization. Windows defines several built-in groups, including Administrators, Users, and Guests.
<AUTHORIZATION>< authorization >
< allow roles=”Domain_NameAdministrators” / >   < !– Allow Administrators in domain. — >
< deny users=”*”  / >                            < !– Deny anyone else. — >
< /authorization >

74. What is Cross Page Posting?

When we click submit button on a web page, the page post the data to the same page. The technique in which we post the data to different pages is called Cross Page posting. This can be achieved by setting POSTBACKURL property of  the button that causes the postback. Findcontrol method of PreviousPage can be used to get the posted values on the page to which the page has been posted.

75. How can we apply Themes to an asp.net application?

We can specify the theme in web.config file. Below is the code example to apply theme:



<pages theme=”Windows7″ />



76: What is RedirectPermanent in ASP.Net?

RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.

77: What is MVC?

MVC is a framework used to create web applications. The web application base builds on  Model-View-Controller pattern which separates the application logic from UI, and the input and events from the user will be controlled by the Controller.

78. Explain the working of passport authentication.

First of all it checks passport authentication cookie. If the cookie is not available then the application redirects the user to Passport Sign on page. Passport service authenticates the user details on sign on page and if valid then stores the authenticated cookie on client machine and then redirect the user to requested page

79. What are the advantages of Passport authentication?

All the websites can be accessed using single login credentials. So no need to remember login credentials for each web site.

Users can maintain his/ her information in a single location.

80. What are the asp.net Security Controls?

<asp:Login>: Provides a standard login capability that allows the users to enter their credentials
<asp:LoginName>: Allows you to display the name of the logged-in user
<asp:LoginStatus>: Displays whether the user is authenticated or not
<asp:LoginView>: Provides various login views depending on the selected template
<asp:PasswordRecovery>:  email the users their lost password

81.How do you register JavaScript for webcontrols ?

We can register javascript for controls using <CONTROL -name>Attribtues.Add(scriptname,scripttext) method.

82. In which event are the controls fully loaded?

Page load event.

83.what is boxing and unboxing?

Boxing is assigning a value type to reference type variable.
Unboxing is reverse of boxing ie. Assigning reference type variable to value type variable.

84. Differentiate strong typing and weak typing

In strong typing, the data types of variable are checked at compile time. On the other hand, in case of weak typing the variable data types are checked at runtime. In case of strong typing, there is no chance of compilation error. Scripts use weak typing and hence issues arises at runtime.

85. How we can force all the validation controls to run?

The Page.Validate() method is used to force all the validation controls to run and to perform validation.

86. List all templates of the Repeater control.?

87. List the major built-in objects in ASP.NET?

88. What is the appSettings Section in the web.config file?

The appSettings block in web config file sets the user-defined values for the whole application.
For example, in the following code snippet, the specified ConnectionString section is used throughout the project for database connection:
<add key=”ConnectionString” value=”server=local; pwd=password; database=default” />

89.Which data type does the RangeValidator control support?

The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.

90. What is the difference between an HtmlInputCheckBox control and an HtmlInputRadioButton control?

In HtmlInputCheckBoxcontrol, multiple item selection is possible whereas in HtmlInputRadioButton controls, we can select only single item from the group of items.

91. Which namespaces are necessary to create a localized application?



92. What are the different types of cookies in ASP.NET?

Session Cookie – Resides on the client machine for a single session until the user does not log out.

Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.

93. What is the file extension of web service?

Web services have file extension .asmx..

94. What are the components of ADO.NET?

The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.

95. What is the difference between ExecuteScalar and ExecuteNonQuery?

ExecuteScalar returns output value where as ExecuteNonQuery does not return any value. ExecuteScalar used for fetching a single value and ExecuteNonQuery used to execute Insert and Update statements.

96.What data types do the RangeValidator control support?

Integer, String, and Date.

97.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.

98.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.

99.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.

100.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.

101.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.

102.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.

103.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.

104.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.

105.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.

106.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.

107.Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines?

The Application_Start event is guaranteed to occur only once throughout the lifetime of the application. It’s a good place to initialize global variables. For example, you might want to retrieve a list of products from a database table and place the list in application state or the Cache object.
SessionStateModule exposes both Session_Start and Session_End events.

108.What are ASP.NET Web Forms? How is this technology different than what is available though ASP?

Web Forms are the heart and soul of ASP.NET Web Forms are the User Interface (UI) elements that give your Web applications their look and feel. Web Forms are similar to Windows Forms in that they provide properties, methods, and events for the controls that are placed onto them. However, these UI elements render themselves in the appropriate markup language required by the request, e.g. HTML. If you use
Microsoft Visual Studio .NET, you will also get the familiar drag and drop interface used to create your UI for your Web application.