简体   繁体   English

如何在AJAX UpdatePanel中保持div的高度和宽度

[英]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.onloadwindow.resizeGMap1分配宽度和高度:

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.

相关问题 如何将图像保持在具有固定宽度和高度的div内,而将其余图像隐藏起来? - How do I keep an image inside a div with a set width and height, but keep the rest of the image hidden? 如何在固定宽度和高度的div中对齐四个圆圈 - how to align four circles inside a div which of fixed width and height 如何在具有使用宽度的图像内部的div上使用height():100% - How to use height() on a div with an image inside that's using width: 100% 如何计算内部有一些文本和固定宽度的div的高度 - how to calculate the height of a div with some text inside and a fixed width 如何在div内动态添加div,直到父div的宽度和高度已满/已完成 - How to add div's inside a div dynamically until the width and height of parent div is full/completed 如何保持div的宽度相同? - How to keep width of div the same? 如何保持由max-width,max-height构成的div形状? - How can i keep shape of div constructed by max-width, max-height? 如何让 div 中的文本在扩展 div 内保持相同的大小宽度 - How to have text in a div keep the same size width inside of an expanding div 如何使用当前div宽度/高度作为最小宽度/高度? - How to use current div width/height as minimum width/height? 宽度和高度减小时如何在div内停止文本更改(灵活填充) - How to stop the text to change(flexible Padding) inside div while width and height are being decreased
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM