...

View Full Version : onload event doesn't fire, pls. help



Lars VJ
12-15-2009, 10:59 AM
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

gusblake
12-15-2009, 11:19 AM
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?

Lars VJ
12-15-2009, 12:17 PM
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.

gusblake
12-15-2009, 12:21 PM
Can you post the page?

Lars VJ
12-15-2009, 12:30 PM
<%@ 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').scroll Height;
}
}
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').scroll Height;
}
}
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').scroll Height;
}*/
}
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
12-15-2009, 12:31 PM
I have ended up simplifying things, so there's only an alert() which should work, but also doesn't...

gusblake
12-15-2009, 12:44 PM
Hmm that works fine for me as an HTML page; it must be your serverside code that's causing the error.

Lars VJ
12-15-2009, 02:24 PM
It was. It turned out that the server side code generated its own onload thingy... thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum