【问题标题】:Keep page position on postback在回发中保持页面位置
【发布时间】:2011-10-05 06:05:45
【问题描述】:

我有一个问题:

    <asp:LinkButton ID="LinkEdit" runat="server" CssClass="right_bottom" 
        onclick="LinkEdit_Click" Height="16px">edit</asp:LinkButton>
    <asp:LinkButton ID="Linkhide" runat="server" CssClass="right_bottom" 
        onclick="Linkhide_Click" Visible="False" hide</asp:LinkButton>
    <br />
    <hr style="width: 740px; height: -6px; margin-left: 0px; " />
    <asp:Label ID="labelFullname" runat="server" Text="Full Name" CssClass="left_top"></asp:Label>
    <asp:Label ID="labelNameDisplay" runat="server" Text="Put name here" CssClass="right_top"></asp:Label>

    <br />
    <asp:Panel ID="panelName" runat="server" Height="240px" Visible="False" CssClass="panel_top"
        style="text-align: left;">
        
        <asp:Label ID="Label8" runat="server" CssClass="left" Text="Please allow 24 hours for name changes to take effect."></asp:Label>
    <div align="center"><br />
    <br />
    <table>
       <tr>
       <td class="label_new">
         <asp:Label ID="Label4" runat="server" Text="Full Name:" ToolTip="Name Displayed"></asp:Label>
         </td>
         <td align="left">
          
          <asp:DropDownList ID="DropDownList1"  runat="server" BorderStyle="Groove" 
                 Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="25px" 
          valign="middle" Width="250px">
              <asp:ListItem></asp:ListItem>
              <asp:ListItem></asp:ListItem>
              <asp:ListItem></asp:ListItem>
          </asp:DropDownList>
       </td>
  </tr>
  

   <tr>
       <td class="label_new">
         <asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
         </td>
         <td align="left">
         <asp:TextBox ID="txtFirstName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px" 
          valign="middle" Width="242px"></asp:TextBox>
       </td>
  </tr>

     <tr>
       <td class="label_new">
         <asp:Label ID="Label9" runat="server" Text="Middle Name:"></asp:Label>
         </td>
         <td align="left">
         <asp:TextBox ID="txtMiddleName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px" 
          valign="middle" Width="242px" onfocus="if (this.value == 'optional') {   this.value='';  this.style.color='black';}" />
       </td>
  </tr>

     <tr>
       <td class="label_new">
         <asp:Label ID="Label10" runat="server" Text="Last Name:"></asp:Label>
         </td>
         <td align="left">
         <asp:TextBox ID="txtLastName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px" 
          valign="middle" Width="242px"></asp:TextBox>
       </td>
  </tr>
  <tr>
  <td colspan="2">
      <asp:Button ID="btnSaveChanges" runat="server" Text="Save Changes" 
          onclick="btnSaveChanges_Click" />
  </td>
  </tr>
    </table>
    </div>
   
    </asp:Panel>

我有 4 个这种格式的面板,就像 facebook 上的帐户设置一样。 我的问题是当我显示面板时它只是跳转到页面顶部。

我想像 facebook 那样做。单击并在您单击的位置处打开。

【问题讨论】:

标签: c# asp.net


【解决方案1】:

我不完全确定我的要求是什么。 Facebook 使用大量 ajax 样式回调,这意味着页面不会使用 asp .net 样式回发重新加载。如果您刚刚开始,我建议您在了解 Ajax / JSON / XMLHttpRequest 等详细信息的同时尝试将代码放入 Ajax .Net UpdatePanel。

如果您只是想确保浏览器窗口在回发后保持在相同的滚动条位置,则将页面设置为使用 MaintainScrollPositionOnPostback="true" 指令。

【讨论】:

    【解决方案2】:

    您可以在页面上设置 MaintainScrollPositionOnPostback 属性:

    Page.MaintainScrollPositionOnPostback = true;
    

    或者放在页面声明中

    <%@ Page MaintainScrollPositionOnPostback="true" %> 
    

    【讨论】:

    • 谢谢大家 Page.MaintainScrollPositionOnPostback = true;
    猜你喜欢
    • 2010-11-08
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 2017-10-10
    • 2017-08-02
    相关资源
    最近更新 更多