无法获得更新面板工作的权利 [英] Unable to get Update panel working right

查看:157
本文介绍了无法获得更新面板工作的权利的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌地图apiv3在网站上。我有过,我用code button_click和javascript函数的背后执行一些逻辑更新面板的按钮。

由于该按钮在更新面板,我无法看到萤火虫的监视窗口任何东西,既不是我在javascript函数工作断点。如果没有更新面板,我可以看到手表的执行流程,一切工作正常,但我得到在地图上重新加载。

code在ASPX:

 < ASP:的ScriptManager ID =ScriptManager1=服务器> < / ASP:ScriptManager的>
    < ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件>
        <&的ContentTemplate GT;
            < ASP:按钮的ID =Button1的=服务器的风格=的z-index:1;左:573px;顶:146px;位置:绝对的文本=显示路线的onclick =Button1_Click1/>
        < /&的ContentTemplate GT;
        <&触发器GT;
            < ASP:AsyncPostBackTrigger控件ID =Button1的事件名称=点击/>
        < /触发器>
    < / ASP:的UpdatePanel>

Button_Click1:

 保护无效Button1_Click1(对象发件人,EventArgs的发送)
{
    使用(CON =新的MySqlConnection(服务器=本地主机; UID =根;密码= as64ws;数据库= GMaps实现。))
    DA =新MySqlDataAdapter的(选择路线*其中uid ='A1',CON);
    da.Fill(DSmroute);
    的foreach(在ds.Tables的DataRow - [R [0] .Rows)
    {
        uroute.Add(:R [经纬度]的ToString());
    }
    croute =新的字符串[uroute.Count]
    croute = uroute.ToArray();
    hdncroute.Value =的string.join(与&,croute);
    ScriptManager.RegisterClientScriptBlock(这一点,typeof运算(按钮),路,droute(),真正的);
}

使用Javascript:

 函数droute()
{
    VAR路线= [];
    VAR温度;
    TEMP =的document.getElementById('<%= hdncroute.ClientID%GT;')。值;
    路线= temp.split('和;');
    //循环添加位置和画线
    VAR路径= polyline.getPath();
    对于(VAR I = 0; I< route.length;我++)
        {
            VAR输入=路径[我]
            变种ltln = input.split(,,2);
            变种纬度= parseFloat(ltln [0]);
            变种经度= parseFloat(ltln [1]);
            VAR POS =新google.maps.LatLng(纬度,经度);
            VAR的标记=新google.maps.Marker({位置:POS机,地图:地图});
            path.push(路径[我]);
            google.maps.event.addListener(标记,'点击',showiwindow);
        }
    功能showiwindow(事件)
    {
    iwindow.setContent(< B>坐标是:LT; / B>< BR />纬度:+ event.latLng.lat()+< BR />经度:+ event.latLng。液化天然气());
    iwindow.open(地图,这一点);
    }
}

我不能得到要被显示在地图上的值。 我应该放在更新面板的按钮,或者在更新面板中的地图吗我在哪里去了?


解决方案

我将取消,你有你的逻辑的很大一部分。

我会按一下按钮做一个jquery ajax的张贴到Web服务在您的codebehind这将返回数组回到你的阿贾克斯后,然后在阿贾克斯后的成功部分我会触发你的JavaScript程序。

http://dotnetguts.blogspot.com/2012/01/jquery-ajax-examples-by-calling-aspnet.html

我以上所述就是我要做的,几乎所有的我的谷歌地图调用.......我还没有看到在接近数百页,我已经对这个阅读这样做的更合适的方法学科。请让我知道如果你需要了解更多有关如何执行这种方式。

下面是描述如何做jQuery的阿贾克斯后另一个很好的页面。

调用$ C $从背后Jquery的

I am working on a website using Google maps apiv3. I have a button in an update panel through which I execute some logic using code behind of button_click and a javascript function.

Since the button is in the update panel, I am unable to see anything in watch window of firebug and neither my breakpoints in javascript function work. Without an update panel I can see the execution flow in watch and everything works fine but I get a reload on map.

Code in aspx:

    <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="Button1" runat="server" style="z-index: 1; left: 573px; top: 146px; position: absolute" Text="Show route" onclick="Button1_Click1"/>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click"/>
        </Triggers>
    </asp:UpdatePanel>

Button_Click1:

protected void Button1_Click1(object sender, EventArgs e)
{
    using (con = new MySqlConnection("server=localhost; uid=root;password=as64ws;database=Gmaps"))
    da = new MySqlDataAdapter("select * from routes where uid='a1'", con);
    da.Fill(ds, "mroute");
    foreach (DataRow r in ds.Tables[0].Rows)
    {
        uroute.Add(r["latlng"].ToString());
    }
    croute = new string[uroute.Count];
    croute = uroute.ToArray();
    hdncroute.Value = string.Join("&", croute);
    ScriptManager.RegisterClientScriptBlock(this, typeof(Button), "routes", "droute()", true);
}

Javascript:

function droute()
{
    var route=[];
    var temp;
    temp = document.getElementById('<%= hdncroute.ClientID %>').value;
    route= temp.split('&');
    //Loop to add locations and draw line
    var path= polyline.getPath();
    for(var i=0;i<route.length;i++)
        {
            var input= route[i];
            var ltln = input.split(",",2);
            var lat=parseFloat(ltln[0]);
            var lng=parseFloat(ltln[1]);
            var pos= new google.maps.LatLng(lat,lng);
            var marker= new google.maps.Marker({position:pos,map:map});
            path.push(route[i]);
            google.maps.event.addListener(marker,'click',showiwindow);
        }
    function showiwindow(event)
    {
    iwindow.setContent("<b>Coordinates are:</b><br/>Latitude:"+event.latLng.lat()+"<br/>Longitude:"+event.latLng.lng());
    iwindow.open(map,this);
    } 
}

I cant get the values to be displayed on the map. Should I place the button in update panel or the map in the update panel? Where am I going wrong?

解决方案

I would scrap a good portion of your logic that you have.

I would have the button click do a jquery ajax post to a webservice in your codebehind which would return an array back to your ajax post and then in the success portion of your ajax post I would trigger your javascript routine.

http://dotnetguts.blogspot.com/2012/01/jquery-ajax-examples-by-calling-aspnet.html

What I described above is how I do almost all of my google maps calls.......I haven't seen a more appropriate way of doing this in the close to 100s of pages that I have read on this subject. Please let me know if you need to know more about how to do it this way.

Here is another good page describing how to do the jquery ajax post. :

Call code behind method from Jquery

这篇关于无法获得更新面板工作的权利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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