Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ASP.NET Interview Questions for Beginners and Professionals - Part 1

0.00/5 (No votes)
31 Mar 2014 1  
This ASP.NET Tutorial is an extension to my previous tutorial Top 10 ASP.NET Interview Questions and Answers.

This ASP.NET Tutorial is an extension to my previous tutorial "Top 10 ASP.NET Interview Questions and Answers". In the previous tutorial, the focus was to present you with the most important and top ASP.NET Interview Questions that are normally asked during an ASP.NET developer Interview. Here in this article, I'll try to further extend those important questions as well as add more important questions.

Basically, this is how an interviewer normally does. Interviewer asked a question about a technical concept at high level. If he gets a right answer, he further goes into details related to that particular concept and its implementation details. For example, in the previous article, we asked about the concept of View State in ASP.NET but in this tutorial, we will further explore the View State concept with more questions. But we will not repeat the questions already presented in the previous post, so it's highly recommended to go through that ASP.NET Interview Questions tutorial first.

What are HttpHandlers and HttpModules in ASP.NET?

In order to fully comprehend the concept of HttpHandlers and HttpModules, I have written a detailed ASP.NET Tutorial. Here, I am defining both the concepts as follows:

HttpHandler: ASP.NET Engine uses HttpHandlers to handle specific requests on the basis of its extensions. ASP.NET Page Handler handles all requests coming for (.aspx) pages. We can define our own custom HttpHandler to handle a specific request with a specific extension, say .jpeg, .gif, or .ahmad. But there will always be only one handler for a specific request.

HttpModule: ASP.NET Engine uses HttpModules to inject some specific functionality along with ASP.NET default functionality for all incoming requests regardless of its extensions. There are a number of built-in modules already available in ASP.NET HTTP Pipeline. But we can write our own custom HTTP module to perform some additional functionality (for example, URL rewriting or implementing some security mechanism) for all incoming requests.

<img src="752184/ASP.NETEngine.png" style="border-width: 0px; border-style: solid; width: 266px; height: 400px;" />

What is State Management?

HTTP is a stateless protocol by nature. So, we need some mechanism to preserve state (i.e., state of a webpage, a control or an object, etc.) between subsequent requests to server from one or more clients. And this mechanism is referred as State Management.

What are the State Management Techniques used in ASP.NET?

State Management techniques used in ASP.NET can be categorized in two types:

  1. Client-Side State Management
    • View State
    • Control State
    • Hidden Fields
    • Cookies
    • Query String
  2. Server-Side State Management
    • Application State
    • Session State
    • Profile Properties

What is ViewState? or Explain ViewState as State Management Technique?

ViewState is one of the Client-Side State Management techniques that provide page-level state management, which means state is preserved between subsequent requests to same page. By using this technique, state of the page along with its controls is stored in a hidden form field i.e., "__VIEWSTATE" and this field is again available on the server when page is posted back with HTTP Request.

You can find this hidden field by looking into view source of a .ASPX page as:

<input type="hidden" name="__VIEWSTATE" 
value="wEPDwUKMTM4OTIxNTEzNA9kFgJmD2QWAgIBD2QWAgIDDxYCHgVzdHlsZQV" />

ViewState data is encoded in Base64 String encoded format.

Can we Enable/Disable ViewState?

Yes, ViewState can be enabled or disabled at different levels:

  • Control Level

    ViewState for a specific control can be enabled or disabled by setting EnableViewState property as follows:

    aControl.EnableViewState = false;
  • Page Level

    We can enable/disable ViewState for a complete page as follows:

    <%@ Page Language="C#" EnableViewState="false" %>
  • Application Level

    For whole application, we can enable/disable views in configuration file as follows:

    <pages enableViewState="false">
    	    ....
    	</pages>

What is the Difference between Session.Clear() and Session.Abandon() in ASP.NET?

As we understand, Session is a Collection and it stores data as Key/Value pair. So, Session.Clear() clears all the session values but doesn't destroy the Session. However, Session.Abandon() destroys the session object.

In other words, Session.Clear() is like deleting all files inside a folder (say "Root") but Session.Abandon() means deleting the "Root" folder.

What is the Difference between Application and Session State?

Application state is basically a common data repository for an application's all users and all their sessions. On the other hand, Session state is specific to a single user session.

So, we can store data in application state object that is common for all users of a particular application as follows:

//Set Value
Application["UsersCounter"] = Convert.ToInt32(Application["UsersCounter"]) + 1;
//Retrieve Value
lblUsersCounter.Text = Application["UsersCounter"].ToString();

It's recommended to store smaller size values in application object.

Session object can store data for a specific session of user. Storage and retrieval is also simple just as for application object.

//Set Value
Session["ProductsCount"] = Convert.ToInt32(Session["ProductsCount"]) + 1;
//Retrieve Value
lblProductsCounter.Text = Session["ProductsCount"].ToString();

Interview Questions about Session State Modes and Session_Start/Session_End events in Global.asax are already explained here.

What is the Difference between Label Control and Literal Control?

A Label control in ASP.NET renders text inside <span> tags while a Literal Control renders just the text without any tags.
With Label controls, we can easily apply styles using its CssClass property, however, if we don't want to apply style/formatting, it's better to go for a Literal control.

Hyperlink Vs LinkButton in ASP.NET?

A Hyperlink just redirects to a given URL identified by "NavigateURL" property. However a LinkButton which actually displays a Hyperlink style button causes a postback to the same page but it doesn't redirect to a given URL.

Validation Controls related Interview Questions are already given in the previous post here.

Hopefully, this pool of ASP.NET Interview Questions and Answers along with previous list of Top 10 will be helpful for ASP.NET Developers. Further in Part 2, I'll have more related questions.

Other Recommended Articles

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here