This is my script :
<%
if (TempData["Resultat"] != null){
%>
<script type="text/javascript">
alert('<%: TempData["Resultat"]%>');
</script>
<%
}
%>
In this case pop-up is shown before page loaded, but i want that's appear after page is fully loaded. in Html it's looks like this :
<body onload="happycode() ;">
but i can't use it in MVC i got one master page for all my web application
JavaScript Alert: After Page Loads If you prefer to have the full page visible while the user reads the alert box message, use the onLoad event. To do this, place a function in the document's <head> , then trigger it using the onLoad attribute in the document's <body> tag.
The Window alert() method is used to display an alert box. It displays a specified message along with an OK button and is generally used to make sure that the information comes through the user. It returns a string which represents the text to display in the alert box.
One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.
Alert Box. Use the alert() function to display a message to the user that requires their attention. This alert box will have the OK button to close the alert box. Example: JavaScript Alert Message. alert("This is an alert message box."
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With