[英]How to keep the height and width of a div inside AJAX UpdatePanel
I'm using the library subgurim to work with google maps. 我正在使用图书馆subgurim来处理Google地图。 How to keep the height and width of
GMap1
inside AJAX UpdatePanel
when partial PostBack occurs? 发生部分PostBack时,
GMap1
在AJAX UpdatePanel
保持GMap1
的高度和宽度?
Default.aspx: 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>
This is my javascript code where you assign a width and height to GMap1
in window.onload
and window.resize
: 这是我的JavaScript代码 ,在
window.onload
和window.resize
为GMap1
分配宽度和高度:
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';
}
There is an existing question here that talks about controls in UpdatePanels losing their subscribed JavaScript functions on Partial PostBacks. 这里有一个现有的问题,它讨论UpdatePanels中的控件在部分回发中丢失其已订阅的JavaScript函数。 I strongly recommend reading through this to understand what is happening here, it's a great read with several different solutions!
我强烈建议您通读此书,以了解此处发生的情况,这是一本不错的书,提供了几种不同的解决方案!
The accepted answer from the above link shows you how to rebind events on a Partial Postback in jQuery, which in your case would allow you to set your control width and height again. 上面的链接接受的答案显示了如何在jQuery中的部分回发中重新绑定事件,在您的情况下,这将允许您再次设置控件的宽度和高度。 I'm not sure if you are using jQuery though or just plain JavaScript, but it should at least provide some insight into your problem.
我不确定您是使用jQuery还是纯JavaScript,但是它至少应该提供一些有关您的问题的见解。
The easiest way to achieve what you are trying to do is start using jQuery if you aren't already. 实现尚未实现的最简单方法是开始使用jQuery(如果尚未使用的话)。 Then you can use the code below to bind your events initally, as well as re-bind them after a partial Postback:
然后,您可以使用下面的代码初始化绑定事件,并在部分回发后重新绑定它们:
$(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
});
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.