11 Essential ASP.NET Interview Questions *
Toptal sourced essential questions that the best ASP.NET developers and engineers can answer. Driven from our community, we encourage experts to submit questions and offer feedback.
Hire a Top ASP.NET Developer NowInterview Questions
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?
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.
Given the scenario from this question, what is an alternative that still allows for server-side processing, but does not refresh the entire page?
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.
Does ASP.NET allow and/or require programmers to keep HTML, JavaScript, and C# in separate files? If so, why would they be separated?
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.
Apply to Join Toptal's Development Network
and enjoy reliable, steady, remote Freelance ASP.NET Developer Jobs
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.)
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.
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?
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>");
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?
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.
Given the following list of tools, languages, and techniques that might be used for a web application:
- Identify which of them are categories
- Put the rest of them into the categories you identified
- 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
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.
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?
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.
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.
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>
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.
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:
- It is possible, but unusual, to implement phone number formatting at the database level
- 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
- 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).
You are developing a timesheet entry page that looks like this:
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?
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:
- Checkboxes only send values to the server when checked and are simply omitted when cleared. All other input types always send values.
- 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.
Why Toptal
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.
Looking for ASP.NET Developers?
Looking for ASP.NET Developers? Check out Toptal’s ASP.NET developers.
Dmitry Pavlov
Dmitry is a top-notch developer with over 20 years of experience creating .NET web applications. He mainly deals with ASP.NET Core and Blazor (C#, .NET Core) software development and architecture design these days. Dmitry has received the Microsoft MVP (Developer Technologies) Award nine times and is a capable community leader. He has also received a Master of Science degree in computer science and structural geology and modeling. Clients call him "The Coding Machine."
Show MoreCheryl Hoskins
Cheryl is a developer with strong communication skills who seeks to provide software solutions that delight her clients. She has enjoyed working with React, Node.js, REST APIs, GraphQL, SQL, MongoDB, and JavaScript recently and is ready to start putting her skills to work for you. In addition to her technical background, Cheryl has an MBA and can translate your business requirements into quality software solutions.
Show MoreMihael Pejak
Mihael has been a developer for 10+ years—with 7+ years of experience working with the .NET framework, large system integrations, and enterprise solutions for various industries. He also has a master's degree in information systems. He specializes in enterprise-level application development on the .NET platform. Mihael has worked on numerous successfully delivered projects—working on the front-end and back-end.
Show MoreToptal Connects the Top 3% of Freelance Talent All Over The World.
Join the Toptal community.