Results 1 to 8 of 8

Thread: Call client script on Updatepanel refresh?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Call client script on Updatepanel refresh?

    Anybody have any idea how to do this? I'm trying to update just the bing map I am using in an UpdatePanel because it takes a few seconds load. I need to call a javascript to refresh my pushpins though when the refresh is complete.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Call client script on Updatepanel refresh?

    Use ScriptManager.RegisterStartupScript. This is specifically for updatepanels.

    ScriptManager.RegisterStartupScript(this.getType, "myBingUpdate" "alert('your javascript here');", true);

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Call client script on Updatepanel refresh?

    Where do I put that? In my UpdatePanel OnLoad event?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Call client script on Updatepanel refresh?

    Tried it in the page load and the updatepanel load, both times I got a script error on the page:

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)
    Timestamp: Wed, 10 Mar 2010 20:06:24 UTC


    Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
    Line: 0
    Char: 0
    Code: 0
    URI: http://localhost:2322/SMD%20Web%20Portal/Dashboard.aspx


    ------------------------

    Any thoughts? That's the same error I was getting before when I was trying to load a map with an inline script.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Call client script on Updatepanel refresh?

    Hey,

    Can you show the code that you are using?

    Gary

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Call client script on Updatepanel refresh?

    Sure, here's the javascript:

    Code:
    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
        <script type="text/javascript">
            var map = null;
            
            function MapIt() {
                
                var CurrentPos = null;
                var pinPoint = null;
                var pinPixel = null;
    
                var mypoints = new Array();
    
                var names = document.getElementById("<%=txtName.ClientID%>").value;
                var lat = document.getElementById("<%=txtMapLat.ClientID%>").value;
                var lon = document.getElementById("<%=txtMapLon.ClientID%>").value;
                var pos = document.getElementById("<%=txtPosition.ClientID%>").value;
                var color = document.getElementById("<%=txtColor.ClientID%>").value;
    
                var latlist = lat.split(",");
                var longlist = lon.split(",");
                var namelist = names.split(",");
                var poslist = pos.split(",");
                var colorlist = pos.split(",");
    
                CurrentPos = new VELatLong(latlist[0], longlist[0]);
    
                map = new VEMap('myMap');
                map.LoadMap(CurrentPos, 15, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);
    
                for (var i = 0; i < latlist.length; i++) {
                    try {
                        var latlong = new VELatLong(latlist[i], longlist[i])
                        var shape = new VEShape(VEShapeType.Pushpin, latlong);
                        shape.SetTitle("Truck " + namelist[i]);
                        shape.SetDescription(poslist[i]);
                        
                        /*if (colorlist[i] == "red") {
                            shape.SetFillColor(new VEColor(255, 0, 0, 1.0)); 
                        }
                        else{
                            shape.SetFillColor(new VEColor(0, 255, 0, 1.0));
                        }*/
                        
                        map.AddShape(shape);
    
                        mypoints.push(latlong);
                    }
                    catch (err) {
                    }
    
                }
    
                map.SetMapView(mypoints);
    
                map.ZoomIn();
            };
    
            function body_onload() {
                MapIt();
            }
        </script>
    Then on the page load I added:

    Code:
    ScriptManager.RegisterStartupScript(udpmetrics, Me.GetType, "test", "MapIt();", True)
    It looks like it calls the script ok, but it errors when I ge tto the Loaf map line of it:

    map.LoadMap(CurrentPos, 15, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Call client script on Updatepanel refresh?

    That error indicates that some of the objects aren't ready. What exactly are you doing in this partial postback - are you recreating the map from scratch within the partial postback code? Does the map already exist on the page, and if it does, why not just call MapIt() in a button click (client side) on the page itself?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Call client script on Updatepanel refresh?

    Quote Originally Posted by mendhak View Post
    That error indicates that some of the objects aren't ready. What exactly are you doing in this partial postback - are you recreating the map from scratch within the partial postback code? Does the map already exist on the page, and if it does, why not just call MapIt() in a button click (client side) on the page itself?
    I have a map with about a 100 vehicles positions mapped on it. I am trying to refresh it automatically every 5 minutes to show their current position. There is no user interaction, so I can't do it on a button click. I am recreating the map. Maybe I can just refresh it. Let me try that.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

Posting Permissions

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



Click Here to Expand Forum to Full Width