MaintainScrollPositionOnPostback is not working?

- - Dernière réponse : Whismeril
Messages postés
14037
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
10 décembre 2019
- 15 sept. 2018 à 18:09
Bonjour,
i'm using an asp:GridView within an asp:Panel within an asp:Content page. The GridView has over 100 rows, so I'm using the Panel to provide a vertical scrollbar. I set MaintainScrollPositionOnPostBack="True" in both the <%@ Page %> directive but the GridView jumps right back to the top when the user selects one of the rows. What am I doing wrong?

Thanks,

this is my code for grid

<asp:Panel runat="server" class="tab-pane fade " ID="company_car_admin_panel_layout" role="tabpanel" aria-labelledby="company_car_admin_panel_layout_tab">
<div style="max-height:400px; overflow-y:scroll ; max-width:700px; overflow-x:scroll">
<asp:GridView ID="GridView1" runat="server" CssClass="table table-bordered" AutoGenerateColumns="false" ShowFooter="true"
ShowHeaderWhenEmpty="true" CellPadding="4" ForeColor="#333333" GridLines="None" Width="700px"
DataKeyNames="ID" OnRowCommand="GridView1_RowCommand" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating" OnRowEditing="GridView1_RowEditing"
OnRowDeleting="GridView1_RowDeleting">


<Columns>

<asp:TemplateField HeaderText="Company Car Value">

<ItemTemplate>
<asp:Label Text='<%# Eval("Company_Car_Value") %>' runat="server" />
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox ID="text_company_car_value" Text='<%# Eval("Company_Car_Value") %>' runat="server" />

</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="text_company_car_value_footer" runat="server" />
<asp:RequiredFieldValidator ValidationGroup="car" ID="RequiredFieldValidator1" SetFocusOnError="true" ControlToValidate="text_company_car_value_footer" runat="server" Text="*Company value is Required" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Company Car Code">

<ItemTemplate>
<asp:Label Text='<%# Eval("Company_Car_Code") %>' runat="server" />
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox ID="text_company_car_code" Text='<%# Eval("Company_Car_Code") %>' runat="server" />
</EditItemTemplate>

<FooterTemplate>
<asp:TextBox ID="text_company_car_code_footer" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="car" SetFocusOnError="true" runat="server" ControlToValidate="text_company_car_code_footer" Text="*Company Code is Required" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Company Car Alias">

<ItemTemplate>
<asp:Label Text='<%# Eval("Company_Car_Alias") %>' runat="server" />
</ItemTemplate>

<EditItemTemplate>
<asp:TextBox ID="text_company_car_alias" Text='<%# Eval("Company_Car_Alias") %>' runat="server" />
</EditItemTemplate>

<FooterTemplate>
<asp:TextBox ID="text_company_car_alias_footer" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" SetFocusOnError="true" ValidationGroup="car" runat="server" ControlToValidate="text_company_car_alias_footer" Text="*Company Alias is Required" ForeColor="Red"></asp:RequiredFieldValidator>
</FooterTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="Action" HeaderStyle-Width="100px">

<ItemTemplate>
<asp:LinkButton runat="server" CommandName="edit" ToolTip="edit" Text="<span class='table-icons'><i class='fas fa-edit'></i></span>" style="width:20px;margin-right:7px;"></asp:LinkButton>
<asp:LinkButton runat="server" CommandName="delete" ToolTip="delete" Text="<span class='table-icons'><i class='fas fa-times'></i></span>" style="width:20px;margin-right:7px;" OnClientClick="return confirm('Are you sure you want to delete this record?');"></asp:LinkButton>
</ItemTemplate>

<EditItemTemplate>
<asp:LinkButton runat="server" CommandName="Update" ToolTip="Update" Text="<span class='table-icons'><i class='far fa-save'></i></span>" style="width:20px;margin-right:7px;"></asp:LinkButton>
<asp:LinkButton runat="server" CommandName="Cancel" ToolTip="cancel" Text="<span class='table-icons'><i class='fas fa-times'></i></span>" style="width:20px;margin-right:7px;"></asp:LinkButton>
</EditItemTemplate>

<FooterTemplate>
<asp:LinkButton runat="server" ValidationGroup="car" CausesValidation="true" CommandName="addnew" ToolTip="addnew" Text="<span class='table-icons' style='font-size:22pt;'><i class='far fa-save'></i></span>"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
<asp:PlaceHolder runat="server" ID="company_car_admin_PlaceHolder"></asp:PlaceHolder>
</div>
</asp:Panel>
and this is my code for master page

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeBehind="WEB_SERVICE.aspx.cs" Inherits="SIRH.Layouts.SIRH.WEB_SERVICE" DynamicMasterPageFile="~masterurl/default.master" %>
Afficher la suite 

1 réponse

Messages postés
14037
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
10 décembre 2019
324
0
Merci
Bonjour,

CodeS SourceS est un forum francophone, donc on écrit en français. Ou alors, il y a le forum anglophone à cette adresse.

Dans tous les cas, pour rendre ton code lisible, et donc donner envie à un bénévole de se pencher dessus, merci de lire et d'appliquer ce qui est décrit là
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Commenter la réponse de Whismeril