473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Problem with javascript file in ASP

Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows XP
Pro SP2, IE 7, VS2005, ASP.net 2.0

The problem is that I'm trying to display this news scroller made in a
Javascript file(newsscroller.js) in my ASP page, everything works great in a
normal HTML page, I can see the scroller just fine, but in an ASP page it
just does not show, I get some error message that the control has not been
initialize, so far I've been stuck for 2 days and just about given up on
this and just use a plain HTML page for this script, can anyone help me find
out what's wrong? Below you will find my ASP page and the java script file.

Regards

************* My ASP page *************

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb"
Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

<script type="text/javascript" language="JavaScript"
src="JS/newsscroller.js" />

</head>

<body>

<script type="text/javascript">

var scrollerMain = new NewsScroller("main");

</script>

<div style="float: right; width: 150px; height: 160px;"
onmouseover="javascript:scrollerMain.StopScrolling ();"

onmouseout="javascript:scrollerMain.StartScrolling ();">

<script type="text/javascript">

scrollerMain.Render("floatingNews");

</script>

</div>
<script type="text/javascript">

scrollerMain.LoadXML('http://localhost/news.xml');

</script>

<script type="text/javascript">

scrollerMain.StartScrolling ();

</script>

</body>

</html>

************* The js script ************
// title and copyright notice go here

// API
// These are the functions you will call to use the NewsScroller from your
web page

// NewsScroller_Initialize
// Parameters:
// elmDivForNews: object reference to a DIV element that will be used to
display the news
// Return:
// returns a NewsScroller object, with supporting properties and methods
function NewsScroller ()
{
if (window.NewsScrollerInstance != null)
{
window.alert("Only one NewsScroller control is allowed on a page.");
return;
}
window.NewsScrollerInstance = this;

this.LoadXML = NewsScroller_LoadXML;
this.AddNewsItem = NewsScroller_AddNewsItem;
this.Clear = NewsScroller_Clear;
this.StartScrolling = NewsScroller_StartScrolling;
this.StopScrolling = NewsScroller_StopScrolling;
this.Render = NewsScroller_Render;

// public properties
this.className = "";
this.itemNormalClassName = "";

this.scrollRate = 25;
this.scrollStep = 1;
this.scrollPause = 2000;

// internal use
this.RenderChildren = NewsScroller_RenderChildren;

this.renderedControl = "";
this.itemsText = new Array();
this.itemsLink = new Array();
this.itemCount = 0;

this.scrollEnabled = false;
}

function NewsScroller_LoadXML (sXmlID)
{
this.Clear();
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load(sXmlID);
var xItems = xmlDoc.getElementsByTagName('item');
for (var iNode = 0; iNode < xItems.length; iNode++)
{
var xItem = xItems[iNode];
var xText = xItem.childNodes[0].text;
var xLink = xItem.childNodes[1].text;
this.AddNewsItem(xText, xLink);
} var elmControl = document.getElementById(this.renderedControl);
this.RenderChildren(this.renderedControl);
}

function NewsScroller_AddNewsItem (strText, strLink)
{
this.itemsText[this.itemCount] = strText;
this.itemsLink[this.itemCount] = strLink;
this.itemCount++;
}

function NewsScroller_Clear ()
{
this.StopScrolling ();
var elmControl = document.getElementById(this.renderedControl);
while (elmControl.childNodes.length 0)
elmControl.removeChild(elmControl.childNodes[0]);
this.itemsText = new Array();
this.itemsLink = new Array();
this.itemCount = 0;
}

function NewsScroller_StartScrolling ()
{
if (this.itemCount 0)
{
var sControlName = this.renderedControl;
if (sControlName == null)
{
window.alert ("You must render a control before you can start scrolling
it.");
return;
}
var elmControl = document.getElementById(sControlName);
var elmItem0 = document.getElementById("floatingNews0");
if (this.itemCount 1)
{
var elmItem1 = document.getElementById(sControlName + "1");
this.cySeparator = (elmItem1.offsetTop - elmItem0.offsetTop) -
elmItem0.offsetHeight;
}
else
{
this.cySeparator = 0;
}

if (this.ScrollTimerID == null)
this.ScrollTimerID = window.setInterval(NewsScroller_ScrollNews,
this.scrollRate);
}
}

function NewsScroller_StopScrolling ()
{
window.clearInterval(this.ScrollTimerID);
this.ScrollTimerID = null;
}

function NewsScroller_Render(sControlID)
{
if (sControlID.length == 0)
{
window.alert("You must provide a unique ID for the rendered control.");
return;
}
var elmControl = document.getElementById(sControlID);
if (elmControl != null)
{
window.alert("A NewsScroller with this ID has already been rendered.
Please use a unique ID.");
return;
}
this.renderedControl = sControlID;

// <DIV>
document.write("<div");
document.write(" id=\"" + sControlID + "\"");
document.write(" class=\"" + this.className + "\"");
document.write(" style=\"position: relative; width: 100%; height: 100%;
\"");
document.write(">");

// </DIV>
document.write("</div>");

this.RenderChildren(sControlID);

var dtNow = new Date();
var dtResume = new Date(dtNow.getFullYear(), dtNow.getMonth(),
dtNow.getDate(), dtNow.getHours(), dtNow.getMinutes(), dtNow.getSeconds(),
this.scrollPause);
elmControl = document.getElementById(sControlID);
elmControl.ResumeDateTime = dtResume;
}

// Supporting functions
function NewsScroller_RenderChildren()
{
var sControlID = this.renderedControl;
elmControl = document.getElementById(sControlID);

// <DIV>
elmDiv = document.createElement("div");
elmDiv.style.position = "absolute";
elmDiv.style.left = "0px";
elmDiv.style.width = "100%";
elmDiv.style.height = "100%";
elmDiv.style.overflow = "hidden";
elmControl.appendChild(elmDiv);

for (var nItem = 0; nItem < this.itemCount; nItem++)
{
var sItemName = sControlID + nItem.toString();

var elmP = document.createElement("p");
elmP.id = sItemName;
elmP.style.position = "relative";
elmP.style.top = "0px";
elmP.style.width = "100%";
elmP.className = this.itemNormalClassName;
elmDiv.appendChild(elmP);

var elmA = document.createElement("a");
elmA.className = this.itemNormalClassName;
elmA.href = this.itemsLink[nItem];
elmP.appendChild(elmA);

var tn = document.createTextNode(this.itemsText[nItem]);
elmA.appendChild(tn);

}
}

function NewsScroller_ScrollNews()
{
var ns = window.NewsScrollerInstance;
var sControlName = ns.renderedControl;
if (sControlName.length == 0)
{
window.alert ("Do not call ScrollNews directly. Use the Start method of
the NewsScroller object.");
return;
}
var elmControl = document.getElementById(sControlName);
if (new Date() >= elmControl.ResumeDateTime)
{
// see whether any item is about to reach the top,
var cyOffset = 0;
for (var nItem = 0; nItem < ns.itemCount; nItem++)
{
var sItemName = sControlName + nItem.toString();
var elmItem = document.getElementById(sItemName);
if ((elmItem.offsetTop 0) && ((elmItem.offsetTop - ns.scrollStep) <=
0))
{
// the top of this item has reached the top of the control,
// so pause scrolling for the whole control
var dtNow = new Date();
var dtResume = new Date(dtNow.getFullYear(), dtNow.getMonth(),
dtNow.getDate(), dtNow.getHours(), dtNow.getMinutes(), dtNow.getSeconds(),
ns.scrollPause);
elmControl.ResumeDateTime = dtResume;
cyOffset = elmItem.offsetTop;
}
}
if (cyOffset 0)
{
// control is just now paused, so scroll all items up
// in order to put the top item flush with the top of the control
for (var nItem = 0; nItem < ns.itemCount; nItem++)
{
var sItemName = sControlName + nItem.toString();
var elmItem = document.getElementById(sItemName);
elmItem.style.pixelTop = elmItem.style.pixelTop - cyOffset;
}
}
else
{
// the control is not paused, so scroll every item up by one step
for (var nItem = 0; nItem < ns.itemCount; nItem++)
{
var sItemName = sControlName + nItem.toString();
var elmItem = document.getElementById(sItemName);
elmItem.style.pixelTop -= ns.scrollStep;
}
}
// see whether any items have scrolled off the top
for (var nItem = 0; nItem < ns.itemCount; nItem++)
{
var sItemName = sControlName + nItem.toString();
var elmItem = document.getElementById(sItemName);
if ((elmItem.offsetTop + elmItem.offsetHeight) <= 0)
{
// the bottom of this item has scrolled beyond the top of the control,
// so move it to the bottom of the control
if (ns.itemCount 1)
{
var sBottomItemName;
if (nItem == 0)
sBottomItemName = sControlName + (ns.itemCount - 1).toString();
else
sBottomItemName = sControlName + (nItem - 1).toString();
var elmBottomItem = document.getElementById(sBottomItemName);
elmItem.style.pixelTop = (elmBottomItem.offsetTop +
elmBottomItem.offsetHeight + ns.cySeparator) - (elmItem.offsetTop -
elmItem.style.pixelTop);
}
else
{
elmItem.style.pixelTop = elmItem.parentElement.offsetHeight;
}
}
}
}
}



Feb 21 '07 #1
2 2155
Hi,

verci wrote:
Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows XP
Pro SP2, IE 7, VS2005, ASP.net 2.0

The problem is that I'm trying to display this news scroller made in a
Javascript file(newsscroller.js) in my ASP page, everything works great in a
normal HTML page, I can see the scroller just fine, but in an ASP page it
just does not show, I get some error message that the control has not been
initialize, so far I've been stuck for 2 days and just about given up on
this and just use a plain HTML page for this script, can anyone help me find
out what's wrong? Below you will find my ASP page and the java script file.

Regards
I didn't read the HUGE amount of code you provided (a link to a URL
where the problem can be seen would have been wiser). However, if it
works fine in HTML but not in the ASP.NET page, it often has to do with
the DOCTYPE. According to the DOCTYPE, the browser will parse and
interprete the document differently.

Try to change this line:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

into

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

and tell us if it works better.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 21 '07 #2
Hi

It still does not work, i get a blank page and at the status bar appears an
icon with the text Finish with errors, the error message :

Line: 26
char: 12
error: scrollerMain is undefined
code 0

So I assumed it's an error on the javascript file?, but as I commented
earlier in a plain HTML page works fine. :(
"Laurent Bugnion [MVP]" <ga*********@bluewin.chwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi,

verci wrote:
>Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows
XP Pro SP2, IE 7, VS2005, ASP.net 2.0

The problem is that I'm trying to display this news scroller made in a
Javascript file(newsscroller.js) in my ASP page, everything works great
in a normal HTML page, I can see the scroller just fine, but in an ASP
page it just does not show, I get some error message that the control has
not been initialize, so far I've been stuck for 2 days and just about
given up on this and just use a plain HTML page for this script, can
anyone help me find out what's wrong? Below you will find my ASP page and
the java script file.

Regards

I didn't read the HUGE amount of code you provided (a link to a URL where
the problem can be seen would have been wiser). However, if it works fine
in HTML but not in the ASP.NET page, it often has to do with the DOCTYPE.
According to the DOCTYPE, the browser will parse and interprete the
document differently.

Try to change this line:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

into

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

and tell us if it works better.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Feb 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthias Stern | last post by:
Hello! I've got a Javascript-PHP encoding problem. (1) Here is the short version: ============================== I'm sending a form textfield via Javascript(!) as URL parameter (GET)...
4
by: Federico Bari | last post by:
Good morning all from italy, i have probably a compatibility problem with a html/javascript page. The aim of the code of the file test.htm you find here following (copy the 3 files in the...
4
by: Yaron Cohen | last post by:
Hi, I would like to ask for you help. I have a page that contains few JS files (please see below). The problem is that sometimes one of the files is not loaded (I am using IE 5.5). I get...
4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
4
by: James Pemberton | last post by:
I have recently created a ASP site utilizing Master Pages and all works fine until I want to proces my javascripts. Just to let you know, most of cliewnt side scripting is new to me. But...
2
by: yarra | last post by:
Hi I have problem with rico.js file. we are using the struts client-side validations. Its working fine. Recently i am adding ajax with help of rico.js file. Now my problem is started. i am...
1
exoskeleton
by: exoskeleton | last post by:
Hi..to all expert...i have this situation .. i cant get the value of the file field in the other page..im using a simple javascript like this... example: // this is page1.php <head> ...
4
by: fmaxwell | last post by:
Dear Group I have a very frustrating problem. I have been trying to make it more difficult to access external javascript files by using PHP sessions. This works beautifully locally (both in...
1
by: wenijah | last post by:
Hi everyone! First thank you for reading this post and yes, you probably already see that kind of topic title somewhere but the problem I've got today might be different than the 100 topics I've...
4
by: r_ahimsa_m | last post by:
Hello, I am learning WWW technologies in Linux. I created index.html file which I can browse with Firefox/Konqueror using URL localhost/~robert/rozgloszenia/index.html. The page looks fine but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.