Question

I have been pulling my hair on this for 2 days without success.

As you can read in the subject, I am simply trying to stop the web page from scrolling to the top of the page when a user clicks a link in my GridView. But the GridView is within a ContentPlaceHolder which is set at a master page.

I have looked at all the possible solutions via Google, even a new assembly idead to build jscript code at run time but all have failed.

Here is my master page:

<%@ 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>

And here is one of the above pages with my 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>

...
...

I've tried several solutions, as mentioned above ...

How to persist scroll position using Master Page? ASP page scrolls to top on UpdatePanel update http://www.dotnetspark.com/links/41291-how-to-prevent-master-page-postback-when.aspx http://www.4guysfromrolla.com/articles/111704-1.aspx

The last link looked the most promising, but I think it was written for non-Master page websites that have a simple form.

I also tried the usual solutions to place the SmartNavigation tag and ...

Page.MaintainScrollPositionOnPostBack = true;

None of the above worked.

I suspect it's because I am using a ContentPlaceHolder? Maybe I should place a <div></div> around it? I tried that, but also not working.

Thanks for your support.

Cheers

Was it helpful?

Solution 2

Remove the href="#" and trick the ASP.net page with fancy CSS to look like a blue link with the mouse changing as well. It works.

OTHER TIPS

You can try adding a div tag inside the content place holder and then set the property overflow=scroll. It might work.

 <div style:"overflow=scroll">
 <!--Your code-->
 </div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top