Wednesday, November 14, 2007

Dot Net Interview Questions - Part 7

  1. How do u implement locking concept for dataset?

  2. Asp.net and asp – differences?

Code Render Block

Code Declaration Block

Compiled

Request/Response

Event Driven

Object Oriented - Constructors/Destructors, Inheritance, overloading..

Exception Handling - Try, Catch, Finally

Down-level Support

Cultures

User Controls

In-built client side validation

Session - weren't transferable across servers

It can span across servers, It can survive server crashes, can work with browsers that don't support cookies

built on top of the window & IIS, it was always a separate entity & its functionality was limited.

its an integral part of OS under the .net framework. It shares many of the same objects that traditional applications would use, and all .net objects are available for asp.net's consumption.

Garbage Collection

Declare variable with datatype

In built graphics support

Cultures

  1. How ASP and ASP.NET page works? Explain about asp.net page life cycle?
  2. Order of events in an asp.net page? Control Execution Lifecycle?

Phase

What a control needs to do

Method or event to override

Initialize

Initialize settings needed during the lifetime of the incoming Web request.

Init event (OnInit method)

Load view state

At the end of this phase, the ViewState property of a control is automatically populated as described in Maintaining State in a Control. A control can override the default implementation of the LoadViewState method to customize state restoration.

LoadViewState method

Process postback data

Process incoming form data and update properties accordingly.

LoadPostData method (if IPostBackDataHandler is implemented)

Load

Perform actions common to all requests, such as setting up a database query. At this point, server controls in the tree are created and initialized, the state is restored, and form controls reflect client-side data.

Load event

(OnLoad method)

Send postback change notifications

Raise change events in response to state changes between the current and previous postbacks.

RaisePostDataChangedEvent method (if IPostBackDataHandler is implemented)

Handle postback events

Handle the client-side event that caused the postback and raise appropriate events on the server.

RaisePostBackEvent method(if IPostBackEventHandler is implemented)

Prerender

Perform any updates before the output is rendered. Any changes made to the state of the control in the prerender phase can be saved, while changes made in the rendering phase are lost.

PreRender event
(OnPreRender method)

Save state

The ViewState property of a control is automatically persisted to a string object after this stage. This string object is sent to the client and back as a hidden variable. For improving efficiency, a control can override the SaveViewState method to modify the ViewState property.

SaveViewState method

Render

Generate output to be rendered to the client.

Render method

Dispose

Perform any final cleanup before the control is torn down. References to expensive resources such as database connections must be released in this phase.

Dispose method

Unload

Perform any final cleanup before the control is torn down. Control authors generally perform cleanup in Dispose and do not handle this event.

UnLoad event (On UnLoad method)

Note To override an EventName event, override the OnEventName method (and call base.OnEventName)

  1. What are server controls?
    ASP.NET server controls are components that run on the server and encapsulate user-interface and other related functionality. They are used in ASP.NET pages and in ASP.NET code-behind classes.
  2. What is the difference between Web User Control and Web Custom Control?
    Custom Controls
    Web custom controls are compiled components that run on the server and that encapsulate user-interface and other related functionality into reusable packages. They can include all the design-time features of standard ASP.NET server controls, including full support for Visual Studio design features such as the Properties window, the visual designer, and the Toolbox.
    There are several ways that you can create Web custom controls:
    • You can compile a control that combines the functionality of two or more existing controls. For example, if you need a control that encapsulates a button and a text box, you can create it by compiling the existing controls together.
    • If an existing server control almost meets your requirements but lacks some required features, you can customize the control by deriving from it and overriding its properties, methods, and events.
    • If none of the existing Web server controls (or their combinations) meet your requirements, you can create a custom control by deriving from one of the base control classes. These classes provide all the basic functionality of Web server controls, so you can focus on programming the features you need.

If none of the existing ASP.NET server controls meet the specific requirements of your applications, you can create either a Web user control or a Web custom control that encapsulates the functionality you need. The main difference between the two controls lies in ease of creation vs. ease of use at design time.
Web user controls
are easy to make, but they can be less convenient to use in advanced scenarios. You develop Web user controls almost exactly the same way that you develop Web Forms pages. Like Web Forms, user controls can be created in the visual designer, they can be written with code separated from the HTML, and they can handle execution events. However, because Web user controls are compiled dynamically at run time they cannot be added to the Toolbox, and they are represented by a simple placeholder glyph when added to a page. This makes Web user controls harder to use if you are accustomed to full Visual Studio .NET design-time support, including the Properties window and Design view previews. Also, the only way to share the user control between applications is to put a separate copy in each application, which takes more maintenance if you make changes to the control.
Web custom controls
are compiled code, which makes them easier to use but more difficult to create; Web custom controls must be authored in code. Once you have created the control, however, you can add it to the Toolbox and display it in a visual designer with full Properties window support and all the other design-time features of ASP.NET server controls. In addition, you can install a single copy of the Web custom control in the global assembly cache and share it between applications, which makes maintenance easier.

Web user controls

Web custom controls

Easier to create

Harder to create

Limited support for consumers who use a visual design tool

Full visual design tool support for consumers

A separate copy of the control is required in each application

Only a single copy of the control is required, in the global assembly cache

Cannot be added to the Toolbox in Visual Studio

Can be added to the Toolbox in Visual Studio

Good for static layout

Good for dynamic layout

  1. Application and Session Events
    The ASP.NET page framework provides ways for you to work with events that can be raised when your application starts or stops or when an individual user's session starts or stops:
    • Application events are raised for all requests to an application. For example, Application_BeginRequest is raised when any Web Forms page or XML Web service in your application is requested. This event allows you to initialize resources that will be used for each request to the application. A corresponding event, Application_EndRequest, provides you with an opportunity to close or otherwise dispose of resources used for the request.
    • Session events are similar to application events (there is a Session_OnStart and a Session_OnEnd event), but are raised with each unique session within the application. A session begins when a user requests a page for the first time from your application and ends either when your application explicitly closes the session or when the session times out.

You can create handlers for these types of events in the Global.asax file.

  1. Difference between ASP Session and ASP.NET Session?
    asp.net session supports cookie less session & it can span across multiple servers.
  2. What is cookie less session? How it works?
    By default, ASP.NET will store the session state in the same process that processes the request, just as ASP does. If cookies are not available, a session can be tracked by adding a session identifier to the URL. This can be enabled by setting the following:
  3. How you will handle session when deploying application in more than a server? Describe session handling in a webfarm, how does it work and what are the limits?
    By default, ASP.NET will store the session state in the same process that processes the request, just as ASP does. Additionally, ASP.NET can store session data in an external process, which can even reside on another machine. To enable this feature:
    • Start the ASP.NET state service, either using the Services snap-in or by executing "net start aspnet_state" on the command line. The state service will by default listen on port 42424. To change the port, modify the registry key for the service: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\Port
    • Set the mode attribute of the section to "StateServer".
    • Configure the stateConnectionString attribute with the values of the machine on which you started aspnet_state.

The following sample assumes that the state service is running on the same machine as the Web server ("localhost") and uses the default port (42424):

Note that if you try the sample above with this setting, you can reset the Web server (enter iisreset on the command line) and the session state value will persist.

  1. What method do you use to explicitly kill a users session?Abandon()
  2. What are the different ways you would consider sending data across pages in ASP (i.e between 1.asp to 2.asp)?Session, public properties
  3. What is State Management in .Net and how many ways are there to maintain a state in .Net? What is view state?
    Web pages are recreated each time the page is posted to the server. In traditional Web programming, this would ordinarily mean that all information associated with the page and the controls on the page would be lost with each round trip.
    To overcome this inherent limitation of traditional Web programming, the ASP.NET page framework includes various options to help you preserve changes — that is, for managing state. The page framework includes a facility called view state that automatically preserves property values of the page and all the controls on it between round trips.
    However, you will probably also have application-specific values that you want to preserve. To do so, you can use one of the state management options.
    Client-Based State Management Options:
    View State
    Hidden Form Fields
    Cookies
    Query Strings
    Server-Based
    State Management Options
    Application State
    Session State

    Database Support
  4. What are the disadvantages of view state / what are the benefits?
    Automatic view-state management is a feature of server controls that enables them to repopulate their property values on a round trip (without you having to write any code). This feature does impact performance, however, since a server control's view state is passed to and from the server in a hidden form field. You should be aware of when view state helps you and when it hinders your page's performance.
  5. When maintaining session through Sql server, what is the impact of Read and Write operation on Session objects? will performance degrade?
    Maintaining state using database technology is a common practice when storing user-specific information where the information store is large. Database storage is particularly useful for maintaining long-term state or state that must be preserved even if the server must be restarted.
  6. What are the contents of cookie?
  7. How do you create a permanent cookie?
  8. What is ViewState? What does the "EnableViewState" property do?Why would I want it on or off?
  9. Explain the differences between Server-side and Client-side code?
    Server side code will process at server side & it will send the result to client. Client side code (javascript) will execute only at client side.
  10. Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines?

No comments: