Why should you avoid the excessive use of ViewState in Asp.Net web page?

Automatic state management is a feature that enables server controls to re-populate their values on a round trip without requiring you to write any code. This feature is not free however, since the state of a control is passed to and from the server in a hidden form field.

Since the view state data resides in a hidden form field (__VIEWSTATE); ViewState increases the size of page and results in slow loading of page at browser. You should be aware of when ViewState is helping you and when it is not.

For example, if you are binding a control to data on every round trip , then you do not need the control to maintain it’s view state, since you will wipe out any re-populated data in any case. ViewState is enabled for all server controls by default. To disable it, set the EnableViewState property of the control to false, as in the following example:

< asp:datagrid EnableViewState=”false” datasource=”…” runat=”server”/>
You can also turn ViewState off at the page level. This is useful when you do not post back from a page at all, as in the following example:

< %@ Page EnableViewState=”false” %>
Note that this attribute is also supported by the User Control directiv

Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to Display data in the combo box?

DataValueField

What is LINQ?

LINQ stands for Language Integrated Query.

LINQ is a data querying methodology which provides querying capabilities to .Net languages with syntax similar to SQL query.

LINQ has a set of querying operators that can be used to query in memory object collection, Sql database, XML, etc. LINQ processing engine will then convert the LINQ query to native query specific to the database to execute against the datasource. Since, the querying feature is integrated with the language; one can build an efficient query based on the language of their choice.

With Visual Studio, we have intelligence support and with language support, we have type safety and compile-time error checks.

Define two important properties and methods and events of datagrid?

DataSource is the property of datagrid to give source name like dataset or datatable and DataBind is the method to bind datagrid.

Example:

gridview.DataSource = ds; //ds is the dataset and filled with some data.

gridview.DataBind();

Difference between Eval() and Bind()

Eval():

  • Eval() method provides only for displaying data from a datasource in a control.

Bind():

  • Bind() methods provides for two-way binding which means that it cannot be used to dispaly as well update data from a datasource