Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何根据MultiView(asp.net webform)中的活动视图存储滚动div元素的多个滚动位置_C#_Asp.net_Asp.net Ajax - Fatal编程技术网

C# 如何根据MultiView(asp.net webform)中的活动视图存储滚动div元素的多个滚动位置

C# 如何根据MultiView(asp.net webform)中的活动视图存储滚动div元素的多个滚动位置,c#,asp.net,asp.net-ajax,C#,Asp.net,Asp.net Ajax,令人困惑的标题,但这是我能说的最好的方式 基本上,我目前使用的是一个带有overflow:auto的div,它包含不同的GridView。GridView通过使用多视图与每个包含单个GridView的单独视图进行交换 我想能够存储每个视图的滚动位置,以便根据将切换到的视图设置div的滚动位置 下面是如何设置我的页面 <div id="scrollingDiv" style="height:100%; overflow:auto;"> <div id="gridWrap"&g

令人困惑的标题,但这是我能说的最好的方式

基本上,我目前使用的是一个带有overflow:auto的div,它包含不同的GridView。GridView通过使用多视图与每个包含单个GridView的单独视图进行交换

我想能够存储每个视图的滚动位置,以便根据将切换到的视图设置div的滚动位置

下面是如何设置我的页面

<div id="scrollingDiv" style="height:100%; overflow:auto;">
  <div id="gridWrap">

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline">
  <ContentTemplate>
    <asp:MultiView ID="MultiView1" runat="server">
      <asp:View ID="view1" runat="server">
        <asp:GridView ID="gridView1" runat="server">
        </asp:GridView>
      </asp:View>

      <asp:View ID="view2" runat="server">
        <asp:GridView ID="gridView2" runat="server">
        </asp:GridView>
      </asp:View>
    </asp:Multiview>
  </ContentTemplate>
  </asp:UpdatePanel>

  </div>
</div>
我一直在四处寻找,没有找到适合我的案例的特定内容。我希望能够只使用一个overflow div,但如果我必须为每个视图创建一个单独的overflow div,我会理解的

任何帮助都会很好,
谢谢。

jQuery和一些隐藏字段可以提供帮助。试试这个

    <asp:Hiddenfield ID="hdnCurrentView" runat="server"/>
    <asp:Hiddenfield ID="hdnMultiView1Top" runat="server"/>
    <asp:Hiddenfield ID="hdnMultiView2Top" runat="server"/>        
然后在jqueryready函数中

    $().ready(function() {

        //for storing scroll position of each view in respective hiddenfields
        $(window).scroll(function () {
          if ($("#hdnCurrentView").val() == "View1") {
             $("#hdnMultiView1Top").val($(window).scrollTop());
          }
          else if ($("#hdnCurrentView").val() == "View2") {
             $("#hdnMultiView2Top").val($(window).scrollTop());
          }
        });

        //for restoring scroll position on page load i.e., ready function in jQuery 
        if ($("#hdnCurrentView").val() == "View1") {
           $(window).scrollTop($("#hdnMultiView1Top").val());
        }
        else if ($("#hdnCurrentView").val() == "View2") {
           $(window).scrollTop($("#hdnMultiView2Top").val());
        }

    });
这将保持每个多视图的垂直滚动位置。如果您也想保持水平滚动位置,请为每个视图设置隐藏字段,并使用下面给出的jQuery函数。留给您作为练习

    $(window).scrollLeft(value);  

快乐的编码…;)

太棒了!非常感谢你。我以前和希登菲尔德打过交道,但这一切都成功了。我将用于设置滚动位置的功能设置为“功能页面加载”,它成功了!再次感谢
    $().ready(function() {

        //for storing scroll position of each view in respective hiddenfields
        $(window).scroll(function () {
          if ($("#hdnCurrentView").val() == "View1") {
             $("#hdnMultiView1Top").val($(window).scrollTop());
          }
          else if ($("#hdnCurrentView").val() == "View2") {
             $("#hdnMultiView2Top").val($(window).scrollTop());
          }
        });

        //for restoring scroll position on page load i.e., ready function in jQuery 
        if ($("#hdnCurrentView").val() == "View1") {
           $(window).scrollTop($("#hdnMultiView1Top").val());
        }
        else if ($("#hdnCurrentView").val() == "View2") {
           $(window).scrollTop($("#hdnMultiView2Top").val());
        }

    });
    $(window).scrollLeft(value);