Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question onload event doesn't fire, pls. help

    I have an aspx with javascript, and I used to call a script func whenever the page was loaded. Suddenly it doesn't work. I then tried to simplify things to
    <body onload="alert('hello');"
    and no alert is shown, nor do I get any error. How come the onload event doesn't fire? How do I fix it?

    thanks in advance

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Does that not even work on a blank test page? Do you have a script on your page that sets the onload to something else?

  • #3
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It used to work on this page, but now it suddenly doesn't. I wonder what can have "broken" it. Javascript has not been disabled, because I also have an onunload that works. I only have one onload on the page.

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Can you post the page?

  • #5
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <%@ Import namespace="WebAdmMMI.Utility"%>
    <%@ Page language="c#" Codebehind="ControllerIFPage.aspx.cs" AutoEventWireup="false" Inherits="WebAdmMMI.Code.ControllerIF.ControllerIFPage" %>
    <%@ Import namespace="System.ComponentModel"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>ControllerIFPage</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    		<meta name="CODE_LANGUAGE" content="C#">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    		<LINK rel="stylesheet" type="text/css" href="../../styles/styles.css">
    		<script language="JavaScript" type="text/javascript">
    		function CreateReq()
    		{
    	var xmlhttp=false;
    	/*@cc_on @*/
    	/*@if (@_jscript_version >= 5)
    	// JScript gives us Conditional compilation, we can cope with old IE versions.
    	// and security blocked creation of the objects.
    	 try {
    	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	 } catch (e) {
    	  try {
    	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    	  } catch (E) {
    	   xmlhttp = false;
    	  }
    	 }
    	@end @*/
    	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    		try {
    			xmlhttp = new XMLHttpRequest();
    		} 
    		catch (e) {
    			xmlhttp=false;
    		}
    	}
    	if (!xmlhttp && window.createRequest) {
    		try {
    			xmlhttp = window.createRequest();
    		} 
    		catch (e) {
    			xmlhttp=false;
    		}
    	}
    	return xmlhttp;
    	}
    
    	function fetch(){
    		var xmlhttp=CreateReq();
    		alert ("fetch");
    		xmlhttp.open("GET", "CtrlLoader.aspx?MachinePrefix="+
    		document.getElementById('LblMachinePrefix').value+
    		"&RequestTime="+
    		(new Date()).getTime()+"&method=Refresh",false);//was true
    	 	xmlhttp.onreadystatechange=function() {
    	  		if (xmlhttp.readyState==4) {
    	   			document.getElementById('TxtCtrlConsole').value+=xmlhttp.responseText;
    	   			document.getElementById('TxtCtrlConsole').scrollTop=document.getElementById('TxtCtrlConsole').scrollHeight;
    	  		}
    	 	}
    	 	xmlhttp.send(null);
    	}
    	function Execute() {
    		var xmlhttp=CreateReq();
    		xmlhttp.open("GET", "CtrlLoader.aspx?MachinePrefix="+
    		document.getElementById('LblMachinePrefix').value+
    		"&RequestTime="+(
    		new Date()).getTime()+"&method=Execute&CommandStr="+
    		document.getElementById('TxtCtrlCommandInput').value,false);//was true
    	 	xmlhttp.onreadystatechange=function() {
    	  		if (xmlhttp.readyState==4) {
    	   			document.getElementById('TxtCtrlConsole').value+=xmlhttp.responseText;
    	   			document.getElementById('TxtCtrlConsole').scrollTop=document.getElementById('TxtCtrlConsole').scrollHeight;
    	  		}
    	 	}
    	 	xmlhttp.send(null);
    	 	document.getElementById('TxtCtrlCommandInput').value="";
    	}
    	function timed_fetch()
    	{
    		alert("timed fetch");
    		fetch();
    		setInterval("fetch()",3000);
    	}
    	function KillMySession()
    	{
    	alert("KillMySession");
    		var xmlhttp=CreateReq();
    		xmlhttp.open("GET", "CtrlLoader.aspx?MachinePrefix="+
    		document.getElementById('LblMachinePrefix').value+
    		"&RequestTime="+(
    		new Date()).getTime()+"&method=KillSession",false);//was true
    	 	xmlhttp.onreadystatechange=function() {
    	  		/*if (xmlhttp.readyState==4) {
    	   			document.getElementById('TxtCtrlConsole').value+=xmlhttp.responseText;
    	   			document.getElementById('TxtCtrlConsole').scrollTop=document.getElementById('TxtCtrlConsole').scrollHeight;
    	  		}*/
    	 	}
    	 	xmlhttp.send(null);
    	}
    	
    /*	function kill_aspbtn()
    	{
    	document.getElementById('TxtCtrlConsole').
    	}*/
    		</script> <!-- onload="kill_aspbtn();">-->
    	</HEAD><!--timed_fetch();-->
    	<body onload="alert('hello');" onunload="KillMySession();">
    		<form id="Form1" method="post" runat="server">
    			<P>&nbsp;</P>
    			<P><asp:label id="LblCtrlPgHeadline" runat="server" Width="100%" Font-Bold="True" Font-Size="Large"></asp:label></P>
    			<!--<table border="1" width="100%" height="90%">
    				<tr>
    					<td>
    						<asp:TextBox id="TxtCtrlStatus" runat="server" TextMode="MultiLine" Width="100%" Height="100%"></asp:TextBox></td>
    					<td>-->
    						<table border="0" width="100%" height="90%">
    							<TBODY>
    								<tr>
    									<td></td>
    									<td width="90%"><asp:textbox id="TxtCtrlConsole" runat="server" Width="100%" Height="100%" TextMode="MultiLine"></asp:textbox><!--Height="216px"--></td>
    									<td></td>
    								</tr>
    								<tr height="20">
    									<td></td>
    									<td width="90%" align="right"><input onclick=fetch(); value='<% GetHeadline("CtrlPgRefresh"); %>' type=button name=Submit>
    										<asp:button id="BtnRefresh" runat="server" Width="72px" Text="Refresh" Visible="False"></asp:button></td>
    									<td></td>
    								</tr>
    								<tr height="20">
    									<td></td>
    									<td width="90%"><asp:textbox id="TxtCtrlCommandInput" runat="server" Width="100%"></asp:textbox></td>
    									<td></td>
    								</tr>
    								<tr height="20">
    									<td></td>
    									<td width="90%" align="right"><input onclick=Execute(); value='<% GetHeadline("CtrlPgExecute"); %>' type=button name=Submit2>
    										<asp:button id="BtnExecuteCtrlCmd" runat="server" Width="64px" Text="Execute" Visible="False"></asp:button></td>
    									<td>
    									</td>
    								</tr>
    							</TBODY>
    						</table>
    					<!--</td>
    				</tr>
    			</table>-->
    			<input type=hidden value="<% GetHidenData(); %>" id="LblMachinePrefix"> 
    			<!--<asp:TextBox style="Z-INDEX: 0" id="LblMachinePrefix" runat="server" Visible=False></asp:TextBox>--></form>
    	</body>
    </HTML>

  • #6
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have ended up simplifying things, so there's only an alert() which should work, but also doesn't...

  • #7
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Hmm that works fine for me as an HTML page; it must be your serverside code that's causing the error.

  • #8
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It was. It turned out that the server side code generated its own onload thingy... thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •