我正在使用图书馆subgurim来处理谷歌地图。当发生部分PostBack时,如何在AJAX GMap1
内保持UpdatePanel
的高度和宽度?
Default.aspx:
<div id="mainContent" style="width: 100%; height: 90%;">
<div id="content" style="width: 75%; border-left-style: groove; border-width: 1px;
overflow: auto; float: left;">
<asp:UpdatePanel ID="updtepnl_map" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer runat="server" ID="timer1" OnTick="upt_Tick" Enabled="False">
</asp:Timer>
<cc1:GMap ID="GMap1" runat="server" Key="AIzaSyDPnaewjFYzDu1acq_NorccJ_VNx_nOgio"
Height="100%" Width="100%" Version="3" Language="es" enableServerEvents="true" enableRotation="true"
OnClick="GMap1_Click" OnMapLoad="GMap1_MapLoad" OnMoveEnd="GMap1_MoveEnd" OnDragEnd="GMap1_DragEnd" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Bttn_Search" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Bttn_startRefresh" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="Center_Map" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="CkBxList_ADFSA" />
<asp:AsyncPostBackTrigger ControlID="CkBx_ADFSA" />
<asp:AsyncPostBackTrigger ControlID="CkBx_FEMSA" />
<asp:AsyncPostBackTrigger ControlID="CkBxList_FEMSA" />
<asp:AsyncPostBackTrigger ControlID="ImgBttn_SearchByS" />
<asp:AsyncPostBackTrigger ControlID="ImgBttn_SearchByIP" />
</Triggers>
</asp:UpdatePanel>
</div>
<div id="menu" style="width: 25%; border-style:hidden; border-width: 1px; overflow: auto;">
</div>
<div id="footer">
ADFSA © 2015
</div>
</div>
这是我的 javascript代码,您可以在GMap1
和window.onload
中为window.resize
分配宽度和高度:
var w = window, d = document, e = d.documentElement,
g = d.getElementsByTagName('body'),
x = w.innerWidth || w.clientWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
window.onresize = function () {
var obj3 = document.getElementById('divTop');
var obj1 = document.getElementById('general'),
footer = document.getElementById('footer'),
gmap1 = document.getElementById('GMap1'),
content= document.getElementById('content');
y = w.innerHeight || e.clientHeight || g.clientHeight;
window.content.style.height = y - (obj3.clientHeight + footer.clientHeight) + 'px';
window.menu.style.height = y - (obj3.clientHeight + footer.clientHeight) + 'px';
window.GMap1.style.height = content.clientHeight - 20 + 'px';
window.GMap1.style.width = content.clientWidth - 20 + 'px';
window.GMap1.style.margin = 10 + 'px';
}
window.onload = function () {
var obj3 = document.getElementById('divTop');
var obj1 = document.getElementById('general'),
footer = document.getElementById('footer'),
gmap1 = document.getElementById('GMap1'),
content= document.getElementById('content');
y = w.innerHeight || e.clientHeight || g.clientHeight;
window.content.style.height = y - (obj3.clientHeight + footer.clientHeight) + 'px';
window.menu.style.height = y - (obj3.clientHeight + footer.clientHeight) + 'px';
window.GMap1.style.height = content.clientHeight - 20 + 'px';
window.GMap1.style.width = content.clientWidth - 20 + 'px';
window.GMap1.style.margin = 10 + 'px';
}
答案 0 :(得分:0)
现有的问题here讨论了UpdatePanels中的控件在Partial PostBacks上丢失了他们订阅的JavaScript函数。我强烈建议您阅读本文,了解这里发生了什么,这是一个很好的阅读,有几个不同的解决方案!
上面链接中接受的答案显示了如何在jQuery中重新绑定Partial Postback上的事件,在您的情况下,您可以再次设置控件的宽度和高度。我不确定你是使用jQuery还是只使用简单的JavaScript,但它至少应该提供一些你的问题的洞察力。
如果您尚未实现start using jQuery,那么实现目标的最简单方法就是{{3}}。然后你可以使用下面的代码初始绑定你的事件,并在部分回发后重新绑定它们:
$(document).ready(function() {
// bind your jQuery events here initially
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
// re-bind your jQuery events here
});
希望它有所帮助!