11 Essential ASP.NET Interview Questions *

question badge

The web is inherently stateless, and the ASP.NET server creates new Page instances for each Web Forms request. Describe the two main techniques for creating statefulness—that is, for persisting data across requests despite this limitation. (One is server-side and one is client-side.)

answer badge

One technique is known as view state. When you use view state, the collection of server-side state variables gets serialized and sent to a hidden client-side form field. When the form is submitted back to the server, the serialized string is re-inflated to form the collection of server-side state variables.

Another technique is session state. The collection of objects associated with a user session is persisted in server memory or a database, and a client cookie is used to map each user session to the collection.

question badge

A user of an ASP.NET page enters a value in a field, tabs to the next field, and notices the screen refreshes at that time—the loading icon briefly shows in the browser tab. What is happening in this scenario behind the scenes in the browser and/or the server?

answer badge

The programmer has attached a postback event handler—for example, using the AutoPostBack property of a control. A small bit of JavaScript in the page causes it to submit the form when the control loses focus (or when the value changes, such as with a dropdown control). The server then invokes the event handler, which re-renders the page back to the browser.

question badge

Given the scenario from this question, what is an alternative that still allows for server-side processing, but does not refresh the entire page?

answer badge

One alternative is the partial postback, using a control called an UpdatePanel. With this technique, AJAX is used to make a separate request from the client to the server, which does not submit the whole form. The response re-renders only the panel in question, not the whole page.

A second technique is to bypass native ASP.NET and write your own JavaScript code using jQuery or another way of supporting AJAX.

Find top ASP.NET developers today. Toptal can match you with the best engineers to finish your project.

Hire Toptal’s ASP.NET developers
question badge

Does ASP.NET allow and/or require programmers to keep HTML, JavaScript, and C# in separate files? If so, why would they be separated?

answer badge

ASP.NET uses a system known as code behind to allow all the HTML markup to be in a view file (with the .aspx extension), while the behavior is defined in a separate C# class (the code-behind class, with the .aspx.cs extension). JavaScript is often served as separate files as well.

Keeping things separate allows the person responsible for visual layout to only touch that file, while a different person might be responsible for coding behavior in C#. The layout and behavior can change independently without affecting each other. ASP.NET encourages, but does not enforce, separation in this manner.

question badge

Does ASP.NET allow and/or require programmers to combine HTML, JavaScript, and/or C# in the same file? If so, why would they be combined?

answer badge

It is possible to interleave all three kinds of code in one file, even in the same line of code. Notwithstanding the reasons to keep them separate, there are also some reasons to combine them.

One reason is to be able to include server-calculated values directly in HTML. This example shows a C# expression inside HTML:

<p>Today is <%=DateTime.Today.Format("M d, yyyy")%></p>

Another reason is to inject server-calculated values into JavaScript. This C# example causes the browser to go to a new page after one second:

Response.Write("<script>setTimeout(function() {window.location='" + nextPage + "'}, 1000)</script>");
question badge

The compiler is able to know the name and type of each control on a page, even when you never declare those controls in C# code.

For example, say your HTML contains a control <asp:Label ID="label2".../>, but no label3 control. You can reference label2.Text in C# code without a compile error, but if you try to reference label3.Text, it causes a compile error.

How does the compiler accomplish this?

answer badge

Visual Studio analyzes the .aspx page and auto-generates the declarations into another file—one which is rarely inspected by developers. The declarations are part of the same class using the mechanism of partial classes.

question badge

A page in an application shows a list of clients, with each one rendered as a link to a client detail page. While most of the links work, a bug has been reported that only affects client names containing the ampersand character, such as “Wiley & Sons”. For those clients, when you click on the link, the client detail page only shows “Wiley” and cuts off the rest of the client name.

Why is this happening? Give technical details concerning the link from the list page to the detail page.

answer badge

A careless programmer forgot to URL-encode the URL in the “href” property of the link. For example, the link might be incorrectly rendered in the final HTML as:

<a href="http://example.com/ClientDetail.aspx?ClientId=94&ClientName=Wiley & Sons">Detail for Wiley & Sons</a>

However, the server interprets the & character as a separator between URL arguments. The correct, URL-encoded version is as follows:

<a href="http://example.com/ClientDetail.aspx?ClientId=94&ClientName=Wiley+%26+Sons">Detail for Wiley & Sons</a>
question badge

Given the following list of tools, languages, and techniques that might be used for a web application:

  1. Identify which of them are categories
  2. Put the rest of them into the categories you identified
  3. Very briefly explain the relationships within each category

Here is the list in alphabetical order for your categorizing:

  • AJAX
  • Application server
  • ASP.NET
  • Base64
  • Binary
  • Bootstrap
  • Browser
  • C#
  • Client
  • Client framework
  • Communication protocol
  • Database server
  • HTTP
  • JavaScript
  • jQuery
  • JSON
  • .NET
  • Postback
  • Programming language
  • Serialization format
  • Server-side framework
  • SQL
  • Technique
  • Tier
  • Validation
  • Visual Basic
  • Web Forms
  • XML
answer badge

Server-side frameworks: .NET is the name of a family of frameworks from Microsoft. ASP.NET is a collection of web-related technologies implemented in .NET. Web Forms is a subset of that collection, encapsulating a particular programming model.

Tiers: There are multiple tiers in application architecture. Three of the most common ones are the database server, application server, and browser (also called the client).

Communication protocols: The contract or style of communication used between tiers. HTTP (or HTTPS) is the protocol used between the client and application server.

Serialization formats: How data is converted to and from streams of bytes. Formats include JSON, binary, XML, and Base64 (these can be combined). These are open to interpretation, and some can also be considered encoding schemes.

Programming languages: The database server often uses the language SQL. The application tier uses the languages C# or Visual Basic (usually not mixed). The browser uses the JavaScript language.

Client framework: The browser tier may use code libraries or frameworks, which usually consist of JavaScript and CSS. The client-side frameworks listed are jQuery and Bootstrap.

Techniques: These items each involve different combinations of concepts mentioned above: AJAX, postback, and validation.

Note: An applicant need not come to the exact same conclusion as this list, as there is some ambiguity in terminology. However a discussion of these points can yield insight into the applicant’s thought process.

question badge

Your site requires some repetition. In particular:

  • The same header and footer will appear on most pages
  • Some pages need a condensed version of the header
  • A “donate now” button and graphic will be reused on just four of the pages

You don’t want to duplicate code, so for each of these elements, how do you write it once and make them appear on many pages?

answer badge

For the header and footer, you can use master pages to define a template. Then each content page can refer to the master page instead of repeating the header and footer.

For the few pages that need a condensed header, you can use a separate master page.

For the donate button, you would use a user control.

question badge

What is wrong or suspicious about this analysis of a bug that you received from a tester? What do you think the problem is?

There is a database problem. We can reproduce the issue on the page CustomerEdit.aspx. Whenever users edit a customer record and misformat the phone number, and click Save, it shows an error page. The error happens because the browser sends a PUT request to the database, but the customer table requires a correctly formatted phone number. When it is in the wrong format, sometimes there is a SQL error. The page changes to show “Invalid index: -1”. Also if I query the customer table, some of the phone numbers are not formatted right.

answer badge

There are several statements that show the tester is not understanding the situation very well:

  • The browser would almost never talk directly to the database.
  • The HTTP PUT verb is not likely to be used with ASP.NET Web Forms.
  • It is not likely to be a database error because:
    1. It is possible, but unusual, to implement phone number formatting at the database level
    2. If it was implemented at that level, it would be unlikely to break in a manner that would allow some misformatted values into the database
    3. The error message doesn’t look like a message emitted by a database server

The error message rather suggests a code bug on the server and/or the client, which is more likely related to the phone-number validation function. Specifically, it is probably a failure to check for a -1 result from the IndexOf method in C# (or indexOf in JavaScript).

question badge

You are developing a timesheet entry page that looks like this:

A timesheet entry page consisting of a client dropdown at the top and a variable-length list of time entries; each row contains a description textbox, billable checkbox, and hours textbox

When you implement some server-side behavior in response to selecting an item in the client dropdown, a new bug crops up. The bug can be replicated by checking some of the boxes and then selecting a different client. Then, whatever checkboxes had been checked previously get cleared. Why might this happen?

answer badge

The reason is most likely that a postback event was added to the client dropdown, causing a page refresh, but the viewstate of the checkboxes is not making a round-trip properly. That is to say, the values are not being included in the form submission to the server postback, and/or not being re-rendered during the page refresh.

There are a couple complications with the page’s requirements that make this scenario likely:

  1. Checkboxes only send values to the server when checked and are simply omitted when cleared. All other input types always send values.
  2. When a page requires a variable-length list of controls, it becomes harder to stay within the ASP.NET programming model, so programmers might resort to emitting the controls by code in a manner that does not participate in the round-tripping of values.
* There is more to interviewing than tricky technical questions, so these are intended merely as a guide. Not every “A” candidate worth hiring will be able to answer them all, nor does answering them all guarantee an “A” candidate. At the end of the day, hiring remains an art, a science — and a lot of work.
Submit an interview question
Submitted questions and answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of Toptal, LLC.
All fields are required
Thanks for submitting your question.
Our editorial staff will review it shortly. Please note that submitted questions and answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of Toptal, LLC.
Looking for ASP.NET experts? Check out Toptal’s ASP.NET developers.
Charles Cook, Ph.D.
United States
Charles has a Ph.D. in aerospace engineering and spent three years developing custom data processing and analysis programs for NASA. He specializes in scalable, enterprise-level application development and engineering solutions for exceptionally high throughputs. He is also the founder and owner of GreatVocab.com, for which he developed the core system using novel concepts in data analysis and control theory.
Alexey Ryazhskikh
Russia
Alexey is a software engineer with more than a decade of experience, working mostly in distributed teams. He is skilled in API development and has extensive experience in content management system development and customization. He enjoys finding the right ways using modern technologies and teamwork in solving complex problems.