部分回发后未加载Google地图 [英] Google map is not loaded after partial postback

查看:82
本文介绍了部分回发后未加载Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google Map,可通过单击按钮从数据库中获取latlng来显示标记.为避免回发,我将此按钮放在了更新面板中.

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: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:


Button_Click:

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);
    }


aspx中的Javascript:


Javascript in aspx:

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());
    }


在body onload中,我初始化并加载了地图及其精细图.但是,当我单击按钮时,最终在地图上显示蓝屏(尽管地图控件(如缩放等)仍然存在).我在哪里做错了?请帮忙.


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.

推荐答案

我找到了解决方案.问题出在HiddenField. HiddenField不在更新"面板中,因此我的Javascript函数无法读取数据.

我将HiddenField移到了更新面板中并完成了操作.
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.


这篇关于部分回发后未加载Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆