Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2009, 10:59 AM   PM User | #1
Lars VJ
New to the CF scene

 
Join Date: Dec 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Lars VJ is an unknown quantity at this point
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
Lars VJ is offline   Reply With Quote
Old 12-15-2009, 11:19 AM   PM User | #2
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
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?
gusblake is offline   Reply With Quote
Old 12-15-2009, 12:17 PM   PM User | #3
Lars VJ
New to the CF scene

 
Join Date: Dec 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Lars VJ is an unknown quantity at this point
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.
Lars VJ is offline   Reply With Quote
Old 12-15-2009, 12:21 PM   PM User | #4
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
Can you post the page?
gusblake is offline   Reply With Quote
Old 12-15-2009, 12:30 PM   PM User | #5
Lars VJ
New to the CF scene

 
Join Date: Dec 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Lars VJ is an unknown quantity at this point
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>
Lars VJ is offline   Reply With Quote
Old 12-15-2009, 12:31 PM   PM User | #6
Lars VJ
New to the CF scene

 
Join Date: Dec 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Lars VJ is an unknown quantity at this point
I have ended up simplifying things, so there's only an alert() which should work, but also doesn't...
Lars VJ is offline   Reply With Quote
Old 12-15-2009, 12:44 PM   PM User | #7
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
Hmm that works fine for me as an HTML page; it must be your serverside code that's causing the error.
gusblake is offline   Reply With Quote
Old 12-15-2009, 02:24 PM   PM User | #8
Lars VJ
New to the CF scene

 
Join Date: Dec 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Lars VJ is an unknown quantity at this point
It was. It turned out that the server side code generated its own onload thingy... thanks!
Lars VJ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:02 PM.


Advertisement
Log in to turn off these ads.