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

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

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].mybutton.style.color = "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;
	}
</script>
<form name="beerForm" action="">
    <select name="beer">
        <option selected="selected">Select Beer</option>
        <option>Heineken</option>
        <option>Amstel Light</option>
        <option>Corona</option>
        <option>Corona Light</option>
        <option>Tecate</option>
    </select>

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

 


Question 5 :

What looping structures are there in JavaScript? 

Answer :

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