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

How can we change the writing direction to "right to left"?

The wrting direction of .aspx page can be changed using the HTML dir attribute as shown below.

<body dir="rtl">

This is useful for Arabic/Urdu languages.
How can you prevent server-side Caching in ASP.NET?

Response.Cache.SetNoServerCaching();
This statement prevents the server-side caching.


example:

Write this directive below the Page Directive
<%@ OutputCache Duration="40" VaryByParam="None" %>


In the code behind write this code
protected void Page_Load(object sender, EventArgs e)
{
//Important
Response.Cache.SetNoServerCaching();

Response.Write(DateTime.Now.ToLongTimeString());

}

//It wil prevent Caching even when we have mentioned Caching parameters
// in the OutputCache Directive
In which of these events you would write code for Paging and Sorting in a Repeater?

NOTE: This is objective type question, Please click question title for correct answer.
Which class you would use for pagination in DataList?

PagedDataSouce is the class whose object is used for pagination in
DataList.
It has got properties like AllowPaging,IsFirstPage,IsLastPage,CurrentPageIndex
which work very well for the DataList.
Its object reference is set to the DataSource property of the DataList.
What is HttpForbiddenHandler?

It is a class used to issue the HTTP 403 error
"Forbidden: Access is denied" or "This type of page is not served" error messages.
when an attempt is made to access a resource mapped to this handler.
You can use it to protect your files.
example:

In the Web.Config file
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.aspx" type="System.Web.HttpForbiddenHandler"/>
</httpHandlers>
</system.web>
</configuration>

when you try to open .aspx page, "this type of page is not served" error message will be displayed.
Can we use App_Code folder in a ASP.NET Web application project?

No, App_Code folder cannot be used in ASP.NET Web application project.
It is available in ASP.NET Web Site only.
You can check it, ASP.NET Web Application project: Solition Explorer:-->
Right click root->ASP.NET Folder-->App_Code will not be there.
What is Configuration API ?

The configuration management APIs used in .NET, which enables user to programmatically build any kind of programs or scripts that create, load, and update the Web.config and machine.config configuration files.
What is a MMC Admin Tool?

The MMC Admin Tool is a new admin tool comprising many things which helps to plug into the existing IIS Administration MMC, and enabling the administrator to graphically read or change the common settings within the XML configuration files.
Can we read the ViewState of .aspx page from its source view?

ViewState is the mechanism through which a control maintains its data on postbacks.
It allows us to store data from the properties of controls(default) in a hidden
field known as _ViewState.
By default we cannot read the ViewState. data. It is base-64 encoded.
It coould be possible using suitable encryption/decryption techniques.
Which is the first event handler that fires for a Web Site?

Applicaion_Start is the first event handler that fires.
It is defined in the Global.asax file and fires once only.
Which of these controls is required to display data in a ListView?

NOTE: This is objective type question, Please click question title for correct answer.
What are Cached events?

They are placed in the ViewState of the page and executed on the server side.

example: TextChanged event of the TextBox.
SelectedIndexChanged event of the DropDownList.

To execute them, some postback must occur.
Which of these tags are mapped with HtmlInputButton class?

NOTE: This is objective type question, Please click question title for correct answer.
<?xml version="1.0"?> <configuration> <system.web> <authentication mode="Windows"/> </system.web> </configuration> How can you retreive the authentication mode programatically?

To retreive the authentication mode, write this code snippet in Page_Load()


AuthenticationSection a=(AuthenticationSection) WebConfigurationManager.GetSection("system.web/authentication");

Response.Write(a.Mode.ToString());


Note:

You must include System.Web.Configuration namespace for this code to work,
How many intrinsic objects are there in ASP.NET?

NOTE: This is objective type question, Please click question title for correct answer.
Difference between Response.Write and Response.Output.Write

Response.Write and Response.Output.Write are both used to write messages on the screen

Difference:
1)Response.Output.Write allows us to write a more formatted output:

example:
Response.Output.Write("hello {0}", "asp.net");
//It is Ok
But, Response.Write("hello {0}","asp.net");
//It is wrong


2) As per ASP.NET 3.5, Response.Write has 4 overloads, while Response.Output.Write

has 17 overloads.

example: To write integer,double, boolean values using Response.Write, we are

provided with one overloaded version:-> Response.Write(object obj);

To do the same thing using Response.Output.Write, we are provided with separate

overloaded versions :
ex:1) Response.Output.Write(int s);

2) Response.Output.Write(double s);

3) Response.Output.Write(bool b);
How can we get the path of the Temporary Folder?

Use the Environment variable "TEMP" and pass it in the GetEnvironmentVariable method of the Environment class.

//Code:


Response.Write(Environment.GetEnvironmentVariable("TEMP"));

How can we initialize Session variables in a user -defined class?

example:
if there is a class known as demo and we want to initialze a Session variable
known as "aa", this will be the command

 HttpContext.Current. Session["aa"] = "welcome";

What is the difference between Session["uname"]=TextBox1.Text and Session.Add("uname",TextBox1.Text)?

Session["uname"]=TextBox1.Text and Session.Add("uname",TextBox1.Text) are both
used to assign data from the TextBox1 to a key known as "uname". Both commands will create a row in the Session Object.

Difference:

Session["uname"]=TextBox1.Text ; It uses an indexer to assign the data. The indexer refers to the particular row of the session object. The key "uname" is
used to identify the row.
Assigning data using an indexer is faster and more efficient than assigning the data
using the method--Session.Add("uname",TextBox1.Text)

Why does not the SessionId change after Session.Abandon() method is called?

It is because of the browser Session that is open till the browser is closed.
The browser Session does not allow the browser cookies to be updated.
The browser cookies store the SessionId.
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