Blog Home  Home Feed your aggregator (RSS 2.0)  
artiso Blog - Scroll-Position nach PostBack beibehalten
Neues rund um's Thema .Net
 
 Monday, August 20, 2007

Ist eine ASP.Net Seite scrollbar, gibt es den unschönen Effekt, dass die Seite nach dem Postback wieder ganz oben steht. Ich habe mal eine kleine Beispiel-Seite, die diesen Effekt demonstriert:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="ValuePlanner_2008.Web.INN_ProjectArea.WebForm2" %>
<%@ Register Assembly="cTextBox" Namespace="artiso_lib.UserControls" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
 
 <title>Untitled Page</title>
 </head>
 <body>
 
<form id="form1" runat="server">
 
 <div> 
    <%

   1:  for (int i = 0; i < 50; i++)
   2:        {
   3:            Response.Write(i + "<br>");
   4:        } 
   5:         
    %> 
   </div>
  </form>
 </body>
</html>


Dieses Problem kann man ganz einfach umgehen, indem man in der Page-Direktive das Attribut MaintainScrollPositionOnPostback="true" einfügt, also:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="ValuePlanner_2008.Web.INN_ProjectArea.WebForm2" MaintainScrollPositionOnPostback="true"  %>

Monday, August 20, 2007 10:58:20 AM (Mitteleuropäische Zeit, UTC+01:00)  #    Comments [1]    |   | 
Friday, September 14, 2007 12:58:33 PM (Mitteleuropäische Zeit, UTC+01:00)
Einfach und genial :)
Habe lange gekämpft, danke für die Lösung!
Juli_Ka
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2008 Thomas. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: