Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a Google Map on which I display markers by fetching the latlng's from a database on a Button Click. To avoid postback I put this button in an update panel.
ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            style="z-index: 1; left: 778px; top: 270px; position: absolute; height: 25px" Text="Button" />
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

Button_Click:
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        //Some code to fetch latlng's from database
        //Passing the final needed value to a <asp:HiddenField> at this point
        ScriptManager.RegisterClientScriptBlock(this, typeof(Button), "currentloc", "showcurrent()", true);
    }

Javascript in aspx:
JavaScript
function showcurrent()
    {
     var rec_loc= document.getElementById('<%=currentloc.ClientID %>').value;
     var splitloc=[];
     splitloc= rec_loc.split(',');
     var clat=parseFloat(splitloc[0]);
     var clng=parseFloat(splitloc[1]);
     var cpos= new google.maps.LatLng(clat,clng);
     var cmarker= new google.maps.Marker({icon:'http://www.googlemapsmarkers.com/v1/A/0099FF/', position:cpos,map:map});  
     map.setCenter(cmarker.getPosition());
    }

In body onload I initialize and load the map and its fine. But when I click the button, I end up with a blue screen in the map(the map controls like zoom, etc are still there though). Where am I doing wrong? Please help.
Posted

1 solution

I have found the solution. The issue was with the HiddenField. The HiddenField was not within the Update panel so my Javascript function wasn't able to read the data.

I moved the HiddenField into the update panel and its done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900