Set - 4

Question 1 :

How about 2+5+"8"?

Answer :

Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it's concatenation, so 78 is the result.

Question 2 :

What is the difference between SessionState and ViewState?

Answer :

ViewState is specific to a page in a session. Session state refers to user specific data that can be accessed across all pages in the web application.

Question 3 :

What does the EnableViewStateMac setting in an aspx page do?

Answer :

Setting EnableViewStateMac=true is a security measure that allows ASP.NET to ensure that the viewstate for a page has not been tampered with. If on Postback, the ASP.NET framework detects that there has been a change in the value of viewstate that was sent to the browser, it raises an error - Validation of viewstate MAC failed. 
Use <%@ Page EnableViewStateMac="true"%> to set it to true (the default value, if this attribute is not specified is also true) in an aspx page.

Question 4 :

How to Accessing Elements using javascript?

Answer :

To do something interesting with HTML elements, we must first be able to uniquely identify which element we want. In the example

    <form action="">
    <input type="button" id="useless" name="mybutton" value="doNothing" />

We can use the "getElementById" method (which is generally preferred)
document.getElementById("useless").style.color = "red";
or we can use the older hierarchical navigation method,
document.forms[0] = "blue";
Notice that this uses the "name" attribute of the element to locate it.
# Example of Accessing Elements in a DOM.

<script type="text/javascript" >
	function showStatus() {
		var selectWidget = document.forms.beerForm.elements["beer"];
		var myValue = selectWidget.options[selectWidget.selectedIndex].value;
		alert('You drank a \"'+ myValue +"\"");
		return true;
<form name="beerForm" action="">
    <select name="beer">
        <option selected="selected">Select Beer</option>
        <option>Amstel Light</option>
        <option>Corona Light</option>

    <input type="button" name="submitbutton" value="Drink" onclick="showStatus()" />


Question 5 :

What looping structures are there in JavaScript? 

Answer :

for, while, do-while loops, but no foreach.

Question 6 :

To put a "close window" link on a page ?

Answer :

<a href='javascript:window.close()' class='mainnav'> Close </a>

Question 7 :

How to hide javascript code from old browsers that dont run it?

Answer :

Use the below specified style of comments <script language=javascript> <!-- javascript code goes here // --> or Use the <NOSCRIPT>some html code </NOSCRIPT> tags and code the display html statements between these and this will appear on the page if the browser does not support javascript

Question 8 :

How to comment javascript code?

Answer :

Use // for line comments and
*/ for block comments

Question 9 :

Name the numeric constants representing max,min values ?

Answer :


Question 10 :

What does javascript null mean?

Answer :

The null value is a unique value representing no value or no object.
It implies no object,or null string,no valid boolean value,no number and no array object.

Question 11 :

How do you create a new object in JavaScript?

Answer :

var obj = new Object(); or var obj = {};

Question 12 :

How do you assign object properties?

Answer :

obj["age"] = 17 or obj.age = 17.

Question 13 :

What's a way to append a value to an array?

Answer :

arr[arr.length] = value;

Question 14 :

What is this keyword?

Answer :

It refers to the current object.

Question 15 :

What does the term sticky session mean in a web-farm scenario? Why would you use a sticky session? What is the potential disadvantage of using a sticky session?

Answer :

Sticky session refers to the feature of many commercial load balancing solutions for web-farms to route the requests for a particular session to the same physical machine that serviced the first request for that session. This is mainly used to ensure that a in-proc session is not lost as a result of requests for a session being routed to different servers. Since requests for a user are always routed to the same machine that first served the request for that session, sticky sessions can cause uneven load distribution across servers.

Question 16 :

You have an ASP.NET web application running on a web-farm that does not use sticky sessions - so the requests for a session are not guaranteed to be served the same machine.

Answer :

Occasionally, the users get error message Validation of viewstate MAC failed. What could be one reason that is causing this error?

The most common reason for this error is that the machinekey value in machine.config is different for each server. As a result, viewstate encoded by one machine cannot be decoded by another. To rectify this, edit the machine.config file on each server in the web-farm to have the same value for machinekey.