我已经为此拉头发2天了,但没有成功。
正如您在主题中所读到的,当用户单击我的 GridView 中的链接时,我只是试图阻止网页滚动到页面顶部。但是 GridView 位于母版页上设置的 ContentPlaceHolder 内。
我已经通过谷歌查看了所有可能的解决方案,甚至是一个新的程序集,旨在在运行时构建 jscript 代码,但都失败了。
这是我的母版页:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Attendance.master.cs" Inherits="Attendance_Attendance" %>
<!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>Attendance</title>
<style type="text/css">
.timetablecell {
cursor: pointer;
}
.timetablecell:hover {
background-color: Orange;
}
.smalltext {
font-size: 8pt;
}
.classsize {
font-size: 8pt; display: block;
}
.nowrap {
white-space: nowrap;
}
img {
border: 0;
}
</style>
<asp:ContentPlaceHolder ID="ContentPlaceHolderHead" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="SMan" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
<asp:Panel ID="HeaderPanel" runat="server">
<table width="100%">
<tr valign="middle">
<td style="width: 25%; " valign="middle" align="left" >
<img src="../images/blahblah.jpg" alt="Tec-NQ" />
</td>
<td valign="middle" align="center" style="width: 50%">
<asp:Image ID="Image3" runat="server" ImageUrl="~/images/blahblah2.jpg" /><br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Times New Roman"
Font-Size="1.2em">BLAHBLAHBLAH</asp:Label>
</td>
<td style="width:25%" align="right">
<img src="../images/BLAHBLAH3.jpg" alt="BLAHBLAH" />
</td>
</tr>
</table>
</asp:Panel>
<table width="100%">
<tr>
<td valign="top" style="width:15%">
<asp:Panel ID="MenuPanel" runat="server">
<table>
<tr>
<td>
<h5 style="white-space:nowrap;">Attendance Menu</h5>
</td>
</tr>
<tr>
<td>
<asp:Menu ID="Attendance" ItemWrap="true" Font-Size="10pt" StaticMenuStyle-VerticalPadding="4"
runat="server" StaticMenuItemStyle-VerticalPadding="1">
<Items>
<asp:MenuItem NavigateUrl="~/Attendance/ClassAttendance.aspx" Text="Class Attendance"
Value="Class Attendance"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/Classes.aspx" Text="Classes"
Value="Classes"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/Timetable.aspx" Text="Timetable"
Value="Timetable"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/Roster.aspx" Text="Roster"
Value="Roster"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/ApprovedAbsences.aspx" Text="Approved Absences"
Value="Approved Absences"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Main Menu" Value="Main Menu"></asp:MenuItem>
</Items>
<StaticMenuStyle VerticalPadding="4px" />
</asp:Menu>
<asp:Menu ID="AttendanceReports" ItemWrap="true" Font-Size="10pt" StaticMenuStyle-VerticalPadding="4"
runat="server" StaticMenuItemStyle-VerticalPadding="1">
<Items>
<asp:MenuItem Text="<h5 style='margin-top:10px;margin-bottom:10px'>Reports</h5>" Selectable="false"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/ClassRoles.aspx" Text="Class Logins"
Value="Class Logins"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/StudentsHereToday.aspx" Text="Students Here Today"
Value="Students Here Today"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/StudentAbsences.aspx" Text="Student Absences"
Value="Student Absences"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/StudentKPI.aspx" Text="Student KPI"
Value="Student KPI"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/AttendanceDetailed.aspx" Text="Attendance Detailed"
Value="Attendance Detailed"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/StudentAttendance.aspx" Text="Attendance Summary"
Value="Attendance Summary"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/AttendanceNotMarked.aspx" Text="Attendance Not Marked"
Value="Attendance Not Marked"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/AttendanceFullTime.aspx" Text="Attendance Full Time"
Value="Attendance Full Time"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/rptsAttendance/default.aspx" Text="Old Attendance Reports"
Value="Old Attendance Reports"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Attendance/StaffTimetable.aspx" Text="Staff Timetable"
Value="Staff Timetable"></asp:MenuItem>
</Items>
<StaticMenuStyle VerticalPadding="4px" />
</asp:Menu>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="HelpImageButton" runat="server" ImageUrl="/images/helpsm.jpg" AlternateText="HELP" CausesValidation="false" OnClick="Help_Click" />
<!--a href="/Help/Attendance/ClassAttendance.aspx" target="_blank"><img src="/images/helpsm.jpg" alt="HELP" border="0"/></a-->
</td>
</tr>
</table>
</asp:Panel>
</td>
<td valign="top">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</form>
</body>
</html>
这是我的 GridView 的上述页面之一......
<%@ Page Language="C#" MasterPageFile="~/Attendance/Attendance.master"
AutoEventWireup="true" CodeFile="ClassAttendance.aspx.cs"
Inherits="Attendance_ClassAttendance"
Title="Class Attendance" Culture="en-AU"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
...
...
...
<asp:GridView ID="gvStudents" runat="server" AutoGenerateColumns="false" AllowSorting="true" CellPadding="2" ShowFooter="true" DataKeyNames="AttendanceID"
OnRowDataBound="GridView_RowDataBound" OnDataBound="GridView_DataBound" EnableSortingAndPagingCallbacks="False">
...
...
</asp:GridView>
</asp:Content>
...
...
如上所述,我尝试了几种解决方案...
如何使用母版页保持滚动位置? ASP 页面在 UpdatePanel 更新上滚动到顶部 http://www.dotnetspark.com/links/41291-how-to-prevent-master-page-postback-when.aspx http://www.4guysfromrolla.com/articles/111704 -1.aspx
最后一个链接看起来最有希望,但我认为它是为具有简单形式的非母版页网站编写的。
我还尝试了通常的解决方案来放置 SmartNavigation 标签和......
Page.MaintainScrollPositionOnPostBack = true;
以上都没有奏效。
我怀疑这是因为我使用的是 ContentPlaceHolder?也许我应该<div></div>
在它周围放置一个?我试过了,但也没有工作。
谢谢你的支持。
干杯