ASP.NET Interview Questions and Answers (1544) - Page 25

Explain Form level validation and Field level Validation?

Form level validation is the validation step that is done after the filling up of the form is done. It’s usually when the user submits the forms.

Field level validation provides immediate validation of the input given by the user. The events associated with field level validation are KeyDown, KeyPress, textchange, etc.
How do you begin and end secure communication via SSL?

To begin secure communication, specify https in an address. For example:
<a href="https://www.dotnetfunda.com/home.aspx">Secure page. 

</a>


To end secure communication, specify http as, For example:
<a href="http://www.dotnetfunda.com/welcome.aspx">Not secure.

</a>

What is the role of the ASP.NET worker process? What is aspnet_wp.exe?

For faster execution of ASP.NET applications that are primarily based to be hosted on IIS server, the aspnet_wp.exe comes into picture. This file (aspnet_wp.exe) is actually the ASP.NET worker process. The worker process is introduced to actually share the load on the IIS, so that application domains and other services may be maintained by a single worker process.

The aspnet_wp.exe worker process is a part of the Microsoft ASP.NET framework and it is responsible for most of the technical processes in the ASP.NET framework. There may be multiple instances of ASP.NET worker process running on IIS 6 depending on multiple application pools. The worker process handles all the requests passed to the ASP.NET framework, so we can say that it’s actually the main engine that handles all requests pertaining to ASP.NET. For example, when a request for an .aspx page is received by the IIS server, the dll called aspnet_isapi.dll passes this request to the aspnet_wp.exe worker process.
What are GridView and ListView in ASP.NET?

Grid View:

The grid view control is a powerful data grid control that allows you to display an entire collection of data, and sorting, and paging, and perform inline editing.

• DataGrid requires you to write custom code for handling common operations like sorting, paging and manipulation of data in DataGrid.

• DataGrid when bound to DataSource control can only support select operation on DataSource. Updating DataSource through DataGrid can be done only through custom ADO.NET code.

• DataGrid supports a restricted event model.

• DataGrid does not support adaptive rendering on different platforms.

Features of Grid View:

• Enhanced data source binding capabilities (Direct interaction with DataSource without any ADO.NET code)
• Built-in support for sorting and paging functionality
• Improved Design time features(Smart Panel Tag)
• Customized pager user interface with Pager Template property
• Additional Column types(Image Field)
• New Event model which support for pre-event and post-event operations

List View:

ListView is a new databound control. ListView control is similar to GridView, Repeater, and DataList which helps us to display a table of data with some additional features. The list view control is basically an advanced ListBox control which allows you to add rows of data, but it also supports large and small icons, multiple columns, automatic label edit, column re-order, hot-tracking. ListView control can be a hybrid control between GridView and Repeater control. ListView control gives us more control on the rendered HTML output with edit/update/delete feature. Also, ListView control has a built in support for adding new row, sorting, etc.

The four main modes of ListView control are:

Icon - Displays items with large icons and your main text
Small Icon - Displays items with small icons and your main text
List - Displays items with your main text
Detail - Displays items with small icons, your main text, and any other data to be displayed in columns and much more...

Features of List View:
• Can define its own template/Layout/Structure for the data display.
• Edit/Update/Delete capabilities on the data displayed.
• Built-in support for inserting new row.
• Built-in support for sorting
• Supports databinding via DataSource Controls including LINQ DataSource controls.
What is DataPager control, describe it?

The DataPager serves as an external control to provide paging features. The DataPager class is used to page data and to display navigation controls for data-bound controls that implements the IPageableItemContainer interface and also associates the DataPager control with the data bound control. It provides a navigation bar on top or on bottom of the page (or both) to navigate to other pages according to the user's requirement. Below there is a description about different page field types.

NextPreviousPagerField -Enables users to navigate through pages one page at a time, or to jump to the first or last page.

NumericPagerField - Enables users to select a page by page number.

TemplatePagerField - Enables you to create a custom paging UI.

Below is the sample code to create a datapager:

<asp: datapager PageSize="10" ID="DataPager1" runat="server" PagedControlID="ListView1">

<fields>
<asp:nextpreviouspagerfield ButtonType="Link" ShowPreviousPageButton="True" ShowNextPageButton="False"/>
<asp:numericpagerfield />
<asp:nextpreviouspagerfield ButtonType="Link" ShowPreviousPageButton="False" ShowNextPageButton="True" />
</fields>
</asp:datapager>

Explain briefly what is DataList control?

The DataList control is a data bound list control that displays items using templates. The DataList control supports selecting and editing of data. The contents of the DataList control can be manipulated by using templates. It acts as a container of repeated data items. DataList and GridView Web controls can contain child controls that raise events. Therefore, a DataList control may have a child control as part of a template that raises an event. The child control event is "bubbled up” (sent up) to the control's container. The container control raises an event called RowCommand with parameter values. These values allow one to determine which control raised the original event. One is then able to respond to this event. Alternatively, one can write individual event handlers for the child controls.

• Using the DataSourceID property, binding to data source controls, such as SqlDataSource, ObjectDataSource, and XmlDataSource, is supported
• Using the DataSource property, binding to an object that implements the System.Collections.IEnumerable interface is supported
• DataList supports selecting and editing. Typically, the Repeater is mostly used for displaying data records. However, because of event bubbling, one is able to implement more advanced behavior within a Repeater control.
• The display direction of a DataList control can be vertical or horizontal.
• The layout of the DataList control is controlled with the RepeatLayout property.

List of templates available in DataList:
AlternatingItemTemplate - Works in conjunction with the ItemTemplate to provide a layout for all the odd rows with in the layout.

EditItemTemplate - Allows for a row or item to be defined on how it looks and behaves when editing.

FooterTemplate - Allows the last item in the template to be defined.

HeaderTemplate - Allows the first item in the template to be defined.

ItemTemplate - This is used to define a row or layout for each item in the display.

SelectedItemTemplate - It allows for a row or item to be defined on how it looks and behaves when selected.

SeparatorTemplate - This template is used between the items in the template.

Below there is a sample code to create DataList control.

<asp:DataList ID=" dlMyCountry" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Country_Code") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Country_Name") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>

private void BindGrid()
{
string sql = "Select * from Country Order By Country_Name";
SqlDataAdapter da = new SqlDataAdapter(sql, “Yourconnectionstring”);
DataTable dt = new DataTable();
da.Fill(dt);

dlMyCountry.DataSource = dt;
dlMyCountry.DataBind();
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}

What is hidden field control?

Hidden fields technique is widely used in ASP.NET programming. This control enables a developer to store a non-displayed value in the rendered HTML of the page. The HiddenField control is used to store a value that needs to be persisted across multiple postbacks to the server. Hidden fields are html input control with hidden type that store hidden data in the html. An example for a hidden field can look like this in your Web Page as:

<asp:HiddenField ID="MyHiddenField" runat="server" Value=”Hidden field value”/>


It will be hidden to the user that means you can store some value but user cannot able to see that value in a webpage. But you should not keep any sensitive information in hidden field because it is available in a webpage, but user cannot see it directly. You can see the hidden field value by right click on a web page and go to "View Source". There you can see the hidden field value along with html tag available in a web page, so it is not secure.
What is the use of @Page Directive?

@Page Directive is used to specify attributes that affect the page in the .aspx page (content page).

<%@Page Language=”C#” Debug=”true” %>

<%@ Page attribute="value" [attribute="value"...] %>
Eg:
MasterPageFile
Theme
Title
Trace
What is the difference between web service and remoting?

• Web services may be accessed using HTTP only. Remoting objects may be accessed over any protocol like TCP, SMTP and HTTP etc.
• Web services are stateless whereas Remoting supports for both stateless and with state environment which is achieved using singleton and singlecall activation.
• ASP.Net provides good support to create web services. They are easy to deploy. In comparison, Remoting is little bit complex.
• Web services may be considered very reliable due to the fact that they are hosted on IIS. But in Remoting if IIS is not used then methods like plumbing have to be used to ensure the application reliability.
• Using Web services only a limited number of types may be serialized (XML). Using Remoting, objects like SOAP object, Binary objects and XML objects may be serialized.
• In .Net when we create an application that consumes a web service, the web service may or mayn’t be built using .Net. But while implementing Remoting in .Net both the applications must be built in .Net.
What is App_Data Folder?

The App_Data folder holds the data stores utilized by the application. The App_Data folder can contain Microsoft SQL Express file (.mdf files), Microsoft Access files (.mdb files), XML files and any other file you want to keep.
What are the different ASP.Net controls?

The ASP.Net framework contains over 70 controls. These controls can be divided into 7 groups:

1) Standard Controls: The standard controls enables you to render standard form elements such as buttons, input fields and labels.

2) Validation Controls: The validation controls enable you to validate form data before you submit the data to the server. For example, you can use a RequiredFieldValidator control to check whether a user entered a value for a required input field.

3) Rich Controls: The Rich controls enable you to render things such as calendars, file upload buttons, rotating banner advertisements and multi-step wizards.

4) Data Controls: The data controls enable you to work with data such as database data. For example, you can use these controls to submit new records to a database table or display a list of database records.

5) Navigation Controls: The navigation controls enable you to display standard navigation elements such as menus, tree views, and bread crumb trails.

6) Login Controls: The login controls enable you to display login, change password, and registration forms.

7) HTML Controls: The HTML controls enable you to convert any HTML tag into a server-side control.
What are the different types of server controls present in ASP.Net? When you will use them?

ASP.Net provides two distinct types of server controls i.e. HTML server controls and Web server controls.
HTML Server: When converting traditional ASP 3.0 web pages to ASP.Net web pages.
When you want to explicitly control the code that is generated for the browser.

Web Server: When you require a richer set of functionality to perform complicated page requirements.
When you are developing web pages that will be viewed by a multitude of browser types and that require different code based upon these types.
Explain about the readystate property in ASP.NET?

Readystate property is a property that can hold the responses of the server to the query that is generated from the client side. Each time when the readystate property changes, then the onreadystatechange function will be executed. Some of the values for the readystate property are as below...

• If the status is zero the request is not initialized

• If the status is one the request has been set up

• If the status is two the request has been sent

• If the status is three the request is in process

• If the status is four the request is complete.
What are new things with ASP.Net 4 WebForms?

Some of the Features are:

• Ability to set Metatags.
• More control over viewstate.
• Added and Updated browser definition files.
• ASP.Net Routing.
• The ability to Persist Selected rows in data Control.
• More control over rendered HTML in FormView and ListView Controls.
• Filtering Support for datasource Controls.
What is RedirectPermanent in ASP.Net 4.0?

In earlier Versions of .Net, Response.Redirect was used, which issues an HTTP 302 Found or temporary redirect response to the browser (meaning that asked resource is temporarily moved to other location) which inturn results in an extra HTTP round trip. ASP.NET 4.0 however, adds a new RedirectPermanent that Performs a permanent redirection from the requested URL to the specified URL. and returns 301 Moved Permanently responses.
E.g .
 RedirectPermanent("/newpath/foroldcontent.aspx");

How will you specify what version of the framework your application is targeting?

In Asp.Net 4.0 a new element "targetFramework" of compilation tag (in Web.config file) lets you specify the framework version in the web.config file as

<?xml version="1.0"?>

<configuration>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
</configuration>


It only lets you target the .NET Framework 4.0 and later versions.
What are different classes that are present in .Net framework?

Below are few classes that are present in .Net framework...

A) File class- It enables you to represent a file on your hard drive. You can use the file class to check whether a file exist or not, create a new file, delete a file, and also can perform many other file related tasks.

B) Graphics class- It enables you to work with different types of images such as GIF, PNG, BMP and JPEG images. You can use the Graphics class to draw rectangles, arcs, ellipse and other elements on an image.

C) Random class- It enables you to generate a random number.

D) SmtpClient class- It enables you to send email. You can use SmtpClient class to send emails that contain attachments and HTML content.

These are only four examples of classes in the framework. The .Net framework contains almost 13,000 classes that you can use when building applications.
What are the new features you can find in Asp.Net 4.0?

ASP.Net 4.0 has below mentioned features as compared to earlier versions such as

• Web.config File Refactoring
• Extensible Output Caching
• Auto-Start Web Applications
• Permanently Redirecting a Page by introducing a new method RedirectPermanent()
• Shrinking Session State to shrink session data
• Extensible Request Validation to avoid cross-site scripting (XSS) attacks by adding custom request-validation logic.
• Object Caching and Object Caching Extensibility by introducing a new assembly "System.Runtime.Caching.dll"

It also introduced many new features such as
• jQuery Included with Web Forms and MVC: Built in JQuery support
• Content Delivery Network Support: Enables you to easily add ASP.NET Ajax and jQuery scripts to your Web applications. We can refence JQuery script over http like <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" >
• New Meta tags under HTML Head tag
• Enabling View State for Individual Controls
• Extended Browser Capabilities
• ASP.NET Chart Control to create visually compelling charts for complex statistical or financial analysis
• New Field Templates for URLs and E-mail Addresses
How do you implement the custom output caching?

Create a custom output-cache provider as a class that derives from the new System.Web.Caching.OutputCacheProvider type. You can then configure the provider in the Web.config file by using the new providers subsection of the outputCache element, as shown below:

 <caching>

<outputCache defaultProvider="AspNetInternalProvider">
<providers>
<add name="DiskCache"
type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/>
</providers>
</outputCache>
</caching>


Then specify the newly created and configured custom cache provider as below:
<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>


How do you implement ViewState for a control in ASP.Net 4.0?

In ASP.NET 4.0, Web server controls include a ViewStateMode property that lets you disable view state by default and then enable it only for the controls that require it in the page.

The ViewStateMode property takes an enumeration that has three values:
Enabled, Disabled, and Inherit.

Enabled enables view state for that control and for any child controls that are set to Inherit or that have nothing set.
Disabled disables view state, and
Inherit specifies that the control uses the ViewStateMode setting from the parent control.

 <asp:PlaceHolder ID="PlaceHolder1" runat="server" ViewStateMode="Disabled"> 

Disabled: <asp:Label ID="label1" runat="server" Text="[DeclaredValue]" /><br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server" ViewStateMode="Enabled">
Enabled: <asp:Label ID="label2" runat="server" Text="[DeclaredValue]" />
</asp:PlaceHolder>
</asp:PlaceHolder>

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories