Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 21st, 2007, 11:53 AM
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Converting Client-side to Server-side Code

I'm trying to convert code that was originally client-side into server-side code. It pulls data from several XML feeds, and then uses variables from that data in a news scroller. When client-side with static variables, the data scrolls every 5 seconds. But the server-side example doesn't scroll at all.

Almost everything works fine, except for the setTimeout. When I load the code listed below, I receive this error:
Microsoft JScript runtime error '800a1391'
'window' is undefined
/scroller.asp, line 173

I realize that 'window' is a browser object that cannot be used in server-side code, but I'm not sure how to adjust my code to make it work. If anyone could let me know what I'm doing wrong, that would be great. Thanks.

var pausecontent=new Array()
        var strMessage1 = "This is message 1";
        var strMessage2 = "This is message 2";
        var strMessage3 = "This is message 3";
        pausecontent[0]='<strong>Title 1: ' + strMessage1 + '</strong>'
        pausecontent[1]='<strong>Title 2: ' + strMessage2 + '</strong>'
        pausecontent[2]='<strong>Title 3: ' + strMessage3 + '</strong>'

        * Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
        * This notice MUST stay intact for legal use
        * Visit http://www.dynamicdrive.com/ for this script and 100s more.

        function pausescroller(content, divId, divClass, delay){
        this.content=content //message array content
        this.tickerid=divId //ID of ticker div to display information
        this.delay=delay //Delay between msg change, in miliseconds.
        this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
        this.hiddendivpointer=1 //index of message array for hidden div
        Response.Write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
        var scrollerinstance=this

        //*****************THIS IS WHERE I'M HAVING THE PROBLEM****************************

        if (window.addEventListener) //run onload in DOM2 browsers
        window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
        else if (window.attachEvent) //run onload in IE5.5+
        window.attachEvent("onload", function(){scrollerinstance.initialize()})
        else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
        setTimeout(function(){scrollerinstance.initialize()}, 500)

        // -------------------------------------------------------------------
        // initialize()- Initialize scroller method.
        // -Get div objects, set initial positions, start up down animation
        // -------------------------------------------------------------------

        //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
        this.getinline(this.visiblediv, this.hiddendiv)
        var scrollerinstance=this
        if (window.attachEvent) //Clean up loose references in IE
        window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
        setTimeout(function(){scrollerinstance.animateup()}, this.delay)

        // -------------------------------------------------------------------
        // animateup()- Move the two inner divs of the scroller up and in sync
        // -------------------------------------------------------------------

        var scrollerinstance=this
        if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
        setTimeout(function(){scrollerinstance.animateup()}, 50)
        this.getinline(this.hiddendiv, this.visiblediv)
        setTimeout(function(){scrollerinstance.setmessage()}, this.delay)

        // -------------------------------------------------------------------
        // swapdivs()- Swap between which is the visible and which is the hidden div
        // -------------------------------------------------------------------

        var tempcontainer=this.visiblediv

        pausescroller.prototype.getinline=function(div1, div2){
        div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"

        // -------------------------------------------------------------------
        // setmessage()- Populate the hidden div with the next message before it's visible
        // -------------------------------------------------------------------

        var scrollerinstance=this
        if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
        setTimeout(function(){scrollerinstance.setmessage()}, 100)
        var i=this.hiddendivpointer
        var ceiling=this.content.length
        this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1

        pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
        if (tickerobj.currentStyle)
        return tickerobj.currentStyle["paddingTop"]
        else if (window.getComputedStyle) //if DOM2
        return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
        return 0
Old November 21st, 2007, 05:25 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

You aren't going to be able to eliminate all the client side code as some of it is specific to only the client. From what I see, there isn't much code that you can move to server side because it all appears to deal with manipulating the display of the data. It looks to me like the only thing you could change is code that generates the client side code that populates the array of messages.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firing server side events at client side codes mehdi62b ASP.NET 1.0 and 1.1 Basics 6 May 18th, 2005 09:11 AM
Client Side equivalnet code for Server.Execute() Sujith Manuel General .NET 4 November 16th, 2004 02:32 AM
sharing a server-side variable with client-side pigtail Javascript How-To 6 November 4th, 2004 02:01 AM
Two Client Side vs Server Side issues Milo Classic ASP Professional 5 May 25th, 2004 02:47 PM
Accessing Server Side Data on Client Side steve456 Classic ASP Professional 3 October 15th, 2003 02:33 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.