如何在回发之间保持DragPanelExtender的位置?

时间:2020-03-05 18:51:05  来源:igfitidea点击:

我已经找到这篇文章:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=181&AspxAutoDetectCookieSupport=1

但是我有另外一种情况。我将某些hiddenFields嵌入到母版页中,并尝试在其中存储dragPanel的位置。

我使用javascript来存储dragPanel的位置,然后当用户单击链接时,将加载新页面,但是dragPanel会重置为起始位置。

有没有简单的方法可以做到这一点?

伪代码:

**this is in MasterPage.master**

function pageLoad()

{  

    // call the savePanelPosition when the panel is moved

    $find('DragP1').add_move(savePanelPosition);  

    var elem = $get("<%=HiddenField1.ClientID%>");   

    if(elem.value != "0")
    {

        var temp = new Array();

        temp = elem.value.split(';');

        // set the position of the panel manually with the retrieve value

        $find('<%=Panel1_DragPanelExtender.BehaviorID%>').set_location(new 

Sys.UI.Point(parseInt(temp[0]),parseInt(temp[1])));

    }

}      

function savePanelPosition()

{
    var elem = $find('DragP1').get_element();

    var loc = $common.getLocation(elem);

    var elem1 = $get("<%=HiddenField1.ClientID%>");

    // store the value in the hidden field

    elem1.value = loc.x + ';' + loc.y;

}        

<asp:Button ID="Button1" runat="server" Text="Button"/>

<asp:HiddenField ID="HiddenField1" runat="server" Value="0"

但是,HiddenField在重定向页面foo.aspx中不可见

解决方案

回答

与其将位置信息存储在隐藏字段中,还不如将其存储在cookie中。该信息很小,因此对页面加载性能的影响很小。