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

Can we access value of ViewState in another page?

No,we can not access values of Viestate from one page to another page.
As viewstate is only used at page-level.
So,we can access viewstate in that page onle,where the viewstate is defined.

After navigation,viewstae is lost.
How to Reverse Items in ArrayList?

We can use ArrayList Reverse() method to Reverse items in ArrayList.

For Example:-

System.Collections.ArrayList arr_list = new System.Collections.ArrayList();

arr_list.Add("vishal");
arr_list.Add("rajesh");

arr_list.Reverse();

How to check how many Viewstate has been used in a Page?

With the help of Count property of ViewState statebag,we can check how many Viewstate has been used in a Page.It returns total ViewState in number.

For Example:-

int viewstate_count = Convert.ToInt32(ViewState.Count);


It will show the Number of ViewState used in a Page.
How to remove values from ViewState?

With the help of Remove() static method of ViewState,we can remove items or values from ViewState.

For Example:-

ViewState.Remove("Name");


Where Name is a Key.
How many ways to remove items or keys from ViewState?

NOTE: This is objective type question, Please click question title for correct answer.
How to access values from ViewState?

We can easily get the values from ViewState.

For Example:-
string name = Convert.ToString(ViewState["Name"]);

How to check whether Dropdown-list contains any items or not?

With the help of Dropdonelist Items Count property we can check whether Dropdown-list have any items or not?

For Example:-

int count = ddl_employee_name.Items.Count;
How to check whether object is initialized or not?

We can check with not null in C# and not nothing in VB.Net to check whether object is initialized or not

As

In C#:

Dataset ds = new Dataset();
if(ds!=null)
{
//read data from Dataset
}

In VB.Net
Dim ds as Dataset = Nothing
If(Not ds is Nothing)
{
//read data from Dataset
}

How to access Session variables in any Class?

We use System.Web.HttpContext.Current class to access Session in any class

like

String user_name = Convert.ToString(System.Web.
HttpContext.Current.Session["User_Name"]);

The reason you can call Session in your code-behind is because ASP.Net pages by default extend the System.Web.UI.Page type. This has a Session public property. If you look at the code for this in Reflector you can see that it just calls HttpContext.Current.Session itself (through its own Context property).

In other classes you will not have access to that property, but you can use HttpContext.Current.Session to access the session data instead, as long as you're running in the context of a web application.
Which property of Session ensures that session has been expired?

TimeOut property says that Session has been Expered.
It's in minute.

It Specifies the number of minutes a session can be idle before it is abandoned.The session timeout configuration setting applies only to ASP.NET pages.
How to check all the keys from Session?

With the help of Session.Keys property,
we can get all the keys.

For Example:-

Session["Name"] = "Vishal";

Session["Phone_No"] = "123455667";

foreach (string key in Session.Keys)
{
Response.Write(key + "<br/>");
}


It will return:Name and Phone_No
How to give Panel control look as Group box control?

With the help of GroupingText property of Panel control,we can give panel as a Group box look.

For Example:-

<asp:Panel ID="pnl_project_info" runat="server" GroupingText="Project Information" BorderColor="Blue" BorderWidth="1px" BorderStyle="Solid">

</asp:Panel>

What do you mean by Container controls in Asp.Net?

Controls those can host other controls are called as Container controls.

For Examples:-

Forms,Panels,TabPages inside TabContainer,Division.
How to make a Gridview Editable?

With the help of EditItemTemplate,we can have the edit functionality in Gridview.We write EditItemTemplate inside
TemplateField as shown below:-

<asp:GridView ID="grid_project_details" runat="server" AllowPaging="True">

<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

What is Javascript debugging support in Visual Studio 2008?

In Visual Studio 2008,we can put the break point in any javascript functions and debug like as in code-behind.
What do we mean by Using Keyword?

Using is just a convention or a short-cut method which allows us to access the classes in a namespace by referencing it once.So whenever we want use the classes or methods in them, we can avoid typing the entire namespace hierarchy.

For Example:-

Using System.Data;

using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

Which method do we use to redirect to user to another page without performing a round trip to the Client?

We use Server.Transfer method as it does not round-trip to the server and also we can not see the destination page URLs.

Syntax:-

Server.Transfer("your_page_name.aspx");

Which method is used for redirecting to another website URLs?

Response.Redirect method is the only method which is used for redirecting to another website URLs from within dot net application.
For Example:-
Response.Redirect("http://yahoo.com");

What do we mean by DataTextField in Asp.Net?

DataTextField is related to Dropdownlist control i.e. it's Dropdownlist property.We provide Database Table column to it to display as a Items in Dropdownlist control when it is populated.

For Example:-
ddl_employee.DataTextField = "employee_name";


Here employee_name is my Column Name.
What do we mean by DataValueField in Asp.Net?

DataValueField is related to Dropdownlist control i.e. it's Dropdownlist property.We provide Database Table column to it to display as a Values in Dropdownlist control when it is populated.
When we select any items from Dropdownlist,then we get selected item value.Generally it's primery key column values.

ddl_employee.DataValueField = "employee_id";


Here,employee_id is my Column Name.
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