Tuesday, April 26, 2011

How to solve bing map ajax over SSL https problem, "Microsoft is undefined?"

Add s=1 parameter in the URL reference
https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1

How to show a pushpin with information box by Bing Maps V7.0

How to show a pushpin with information box by Bing Maps V7.0
    <div class='mapb'><a href='#'>Show Map</a></div>
    <div id='BingMapDiv'/>



    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
    </script>
    <script type="text/javascript">
        var map = null;
        var bingmapkey = "<%=Registration.GeoLocation.BingMapKey%>";
        var pinlatlon = "45.410309,-75.674057";
        var pindescription = 'Push pin title';


        function GetMap() {
            map = new Microsoft.Maps.Map(document.getElementById("BingMapDiv"), { credentials: bingmapkey, showCopyright: false, showDashboard: false, showScalebar: false, showMapTypeSelector: false });

            var pinPoint = pinlatlon;
            var pinlocation = map.getCenter();
            if (pinPoint != "") {
                pinlocation = new Microsoft.Maps.Location(pinlatlon.split(",")[0], pinlatlon.split(",")[1]);
            }

            var pin = new Microsoft.Maps.Pushpin(pinlocation);
            pinInfobox = new Microsoft.Maps.Infobox(pinlocation, { title: 'Title', visible: true, description: pindescription });
            Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
            Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);

            map.entities.push(pin);
            map.entities.push(pinInfobox);

            map.setView({ center: pinlocation, zoom: 10 });
        }

        function displayInfobox(e) {
            pinInfobox.setOptions({ visible: true });
        }
        function hideInfobox(e) {
            pinInfobox.setOptions({ visible: false });
        }

        $('.mapb').live('click'function () { $('#BingMapDiv').toggle(); if ($('#BingMapDiv').is(':visible')) GetMap(); });

    </script>


How to force Visual Studio to regenerate the .designer file

Solution 1:
Check html view header if CodeBehind existed
 CodeBehind="~/Your.aspx.cs"

Solution 2:
Reformat or modify html view and check if anything syntax problem for html tags

Solution 3:
   1. Delete the designer.cs file from your project
   2. Rightclick your main aspx file and select “Convert to Web Application“.

Reference: