There are three ways.
The first is to put the script tag on the bottom of the page:
<body>
<!--Body content-->
<script type="text/javascript">
alert('<%: TempData["Resultat"]%>');
</script>
</body>
The second way is to create an onload event:
<head>
<script type="text/javascript">
window.onload = function(){//window.addEventListener('load',function(){...}); (for Netscape) and window.attachEvent('onload',function(){...}); (for IE and Opera) also work
alert('<%: TempData["Resultat"]%>');
}
</script>
</head>
It will execute a function when the window loads.
Finally, the third way is to create a readystatechange
event and check the current document.readystate:
<head>
<script type="text/javascript">
document.onreadystatechange = function(){//window.addEventListener('readystatechange',function(){...}); (for Netscape) and window.attachEvent('onreadystatechange',function(){...}); (for IE and Opera) also work
if(document.readyState=='loaded' || document.readyState=='complete')
alert('<%: TempData["Resultat"]%>');
}
</script>
</head>