[RESOLVED] Repeater control and MaintainScrollPositionOnPostback
Oooh fudgicles,
I have a repeater control and everything works great except. . . Every time the form does a post back, which is often, it scrolls to the top (Grrrr). Unfortunately (and apparently) MaintainScrollPositionOnPostback="true" has no affect on the repeater control. I looked on-line and as is customary in .NET there are plenty of "work-around" solutions plenty of which look promising, none of which I could get to work. The most promising solution involved an UpdatePanel and some JavaScript, but that didn't work because it required a second ScriptManager (you can only have one) and I needed the other for my date picker extension. So all I want is the page to stay where it is on callback (I just hate dealing with irate users) Any suggestions?
Here is the ASP for the repeater:
Code:
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<table class="formTbl" border="0" cellspacing="2px">
<colgroup>
<col width="75px" />
<col width="75px" />
<col width="50px" />
<col width="60px" />
<col width="60px" />
<col width="125px" />
<col width="100px" />
</colgroup>
<tr>
<td class="top" align="center" colspan="7">Sanitary Pipes Cleaned</td>
</tr>
<tr class="grayBack" valign="bottom">
<td align="center">From MH</td>
<td align="center">To MH</td>
<td align="center">Basin</td>
<td align="right">Footage</td>
<td align="center">Size</td>
<td align="center">WorkType</td>
<td align="center">Times Jetted</td>
</tr>
<tr>
<td colspan="7">
<hr />
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:Label ID="From_MH" runat="server" Text='<%# Eval("UP_MH_NO")%>'></asp:Label>
</td>
<td align="center">
<asp:Label ID="To_MH" runat="server" Text='<%# Eval("DN_MH_NO")%>'></asp:Label>
</td>
<td align="center">
<asp:Label ID="Basin" runat="server" Text='<%# Eval("BASIN")%>'></asp:Label>
</td>
<td align="right">
<asp:Label ID="Asbuilt_Length" runat="server" Text='<%# Eval("ASBUILT_LENGTH")%>'></asp:Label>
</td>
<td align="right">
<asp:Label ID="Diameter" runat="server" Text='<%# Eval("DIAMETER")%>'></asp:Label>
</td>
<td align="center">
<asp:DropDownList ID="lstWorkType" runat="server"
AutoPostBack="True" width="125px">
<asp:ListItem Selected="True">Maintenance</asp:ListItem>
<asp:ListItem>Grease</asp:ListItem>
<asp:ListItem>Root Cutting</asp:ListItem>
<asp:ListItem>Televising</asp:ListItem>
<asp:ListItem>Trouble</asp:ListItem>
</asp:DropDownList>
</td>
<td align="center">
<asp:DropDownList ID="lstTimesJetted" runat="server" width="50px"
OnSelectedIndexChanged="lstTimesJetted_SelectedIndexChanged">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr >
<td align="center">Comment:</td>
<td colspan="5">
<asp:TextBox ID="txtComment" runat="server" Width="370px"></asp:TextBox>
</td>
<td >
<asp:Label ID="PipeID" runat="server" Text='<%# Eval("MAIN_ID")%>' Visible="false" ></asp:Label>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<td colspan="7">
<hr />
</td>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And here is the function that is called from the DropDownList that causes the post back:
Code:
Protected Sub lstTimesJetted_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
CalculateFootage()
End Sub
Protected Sub CalculateFootage()
Dim vRepeater1 As Repeater = Repeater1
Dim vAsbuilt_Length As Label
Dim vLstTimesJetted As DropDownList
Dim vItems As RepeaterItemCollection
Dim vItem As RepeaterItem
Dim vAsbLen As Decimal = 0
Dim vJetVal As Decimal = 0
Dim vJetted As Decimal = 0
vItems = vRepeater1.Items
For Each vItem In vItems
vAsbuilt_Length = DirectCast(vItem.FindControl("Asbuilt_Length"), Label)
vLstTimesJetted = DirectCast(vItem.FindControl("lstTimesJetted"), DropDownList)
vAsbLen = CDec(vAsbuilt_Length.Text)
vJetVal = CDec(vLstTimesJetted.SelectedValue)
vJetted = vJetted + (vJetVal * vAsbLen)
Next
txtTotFootage.Text = vJetted.ToString
End Sub
Note: the reason CalculateFootage() is a separate function is because I also call it in the Page_On_Load
Re: Repeater control and MaintainScrollPositionOnPostback
I think you should retry with the updatepanel examples you have.The toolscriptmanager has to be one page(except if you are using a master page) and that's about it.It handles pretty much anything need to be handled by it.
Re: Repeater control and MaintainScrollPositionOnPostback
Agreed.
The ScriptManager (or the ToolScriptManager depending on version) is the entry point control that deals with communicating from the client page back to the server, and only one is required per page, and every AJAX control on the page can use it to communicate, so I don't see why you would require another one.
Can you point us at the link that you found this solution? It would be interesting to take a look.
Gary
Re: Repeater control and MaintainScrollPositionOnPostback
Thanks guys for your feed back. Here is the link:
http://basgun.wordpress.com/2008/06/...anel-postback/
The author uses <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" >
while I was using <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" >
It seemed these were in conflict. I will add the Java script and Update panel again and report on my progress.
OK, tried it and this is the error I get just using the Ajax ToolkitScriptManager:
Quote:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; AskTbARS/5.12.1.16460)
Timestamp: Thu, 28 Jul 2011 14:45:07 UTC
Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<script type="text/j'.
Line: 2
Char: 74704
Code: 0
Re: Repeater control and MaintainScrollPositionOnPostback
Just in case you need it, here is the entire page:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SanPipeCleaning.aspx.vb" Inherits="App_Forms_SanPipeCleaning" Trace="false" MaintainScrollPositionOnPostback="true"%>
<!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>Sanitary Pipe Cleaning form</title>
<script type="text/javascript">
function Body_Onload() {
window.moveTo(0, 0);
window.resizeTo(90, 70);
}
function Body_OnUnload() {
if (window.opener && !window.opener.closed) {
opener.window.document.getElementById("TaskManholes").submit();
}
}
function UtilityInspectionConformation(vMessage) {
window.document.UtilityInspectionConformationForm.MESSAGE.value = vMessage;
var UtilityInspectionConformationForm = window.open('blank.htm', 'UtilityInspectionConformationForm', "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no");
window.document.UtilityInspectionConformationForm.submit();
// To prevent closing parent window error message which
// occurs because the default.aspx window is being closed
window.close();
}
function printMe() {
HideShowButtons("HideElement")
// Print Report
window.print();
HideShowButtons("ShowElement")
}
function HideShowButtons(vMode) {
// Get all elements of type input
var vElements = document.getElementsByTagName('Input');
// For each element . . .
for (i = 0; i < vElements.length; i++) {
var vElement = vElements[i];
// If element of type submit or button
if ((vElement.type == "submit") || (vElement.type == "button")) {
// change element classname to passed parameter
vElement.className = vMode;
}
}
}
</script>
<style type="text/css">
.FormTable
{ border-color: Gray;
background-color: #DAD3CF;
}
.CommentField
{
width: 99%;
font-family: Tahoma;
}
.FixHeight
{ height: 42px;
}
</style>
<link href="../stylesheet/TabbedInspForm.css" rel="stylesheet" type="text/css" />
</head>
<body onload="Body_Onload()" onunload="Body_OnUnload()">
<form name="UtilityInspectionConformationForm" method="post" target="UtilityInspectionConformationForm"
action="UtilityInspectionConformation.aspx">
<input type="hidden" name="MESSAGE" />
</form>
<form id="form1" runat="server" style="background-color:#DAD3CF;" >
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
</ajaxToolkit:ToolkitScriptManager>
<script type="text/javascript">
// The following code is designed to maintain the scroll
// position of the Repeater Control
// It is important to keep this code after the ScriptManager1
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, Args) {
if ($get('<%= Panel1.ClientID %>') != null) {
// Get X and Y positions of scrollbar before the partial postback
xPos = $get('<%= Panel1.ClientID %>').scrollLeft;
yPos = $get('<%= Panel1.ClientID %>').scrollTop;
}
}
function EndRequestHandler(sender, Args) {
if ($get('<%= Panel1.ClientID %>') != null) {
// Set X and Y positions of scrollbar before the partial postback
$get('<%= Panel1.ClientID %>').scrollLeft = xPos;
$get('<%= Panel1.ClientID %>').scrollTop = yPos;
}
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Height="650px">
<table border="1">
<tr>
<td>
<table class="formTbl" border="0" cellspacing="2px">
<colgroup>
<col width="120" align="right"/>
<col width="150"/>
<col width="130" align="right"/>
<col width="150"/>
</colgroup>
<tr>
<td class="top" align="center" colspan="4">Sewer Cleaning Data </td>
</tr>
<tr>
<td>Date:</td>
<td>
<asp:TextBox id="txtDate" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="txtDate_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtDate">
</ajaxToolkit:CalendarExtender>
</td>
<td>Total Footage:</td>
<td>
<asp:TextBox id="txtTotFootage" runat="server" ReadOnly="True" ></asp:TextBox>
</td>
</tr>
<tr>
<td>Hours of Sewer Jet Use:</td>
<td>
<asp:TextBox id="txtJetHours" runat="server"></asp:TextBox>
</td>
<td>Water Used (gal.):</td>
<td>
<asp:TextBox id="txtWtrUsed" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
</td>
<td>Grit Removed (cu.ft.):</td>
<td>
<asp:TextBox id="txtGritRemoved" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center">Select Operators:<br /><i>Select one or<br />use Ctrl to select<br />more than one</i></td>
<td colspan="3">
<asp:ListBox id="lstOperators" runat="server" Width="280px" DataSourceID="SqlDS_Technician"
DataTextField="TechName" DataValueField="TechName"
SelectionMode="Multiple"></asp:ListBox>
</td>
</tr>
<tr>
<td>Location/Purpose:</td>
<td colspan="3">
<asp:TextBox id="txtPurpose" runat="server" Width="420px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<asp:Button ID="btnSubmitCleaning" runat="server" Text="Submit" Width="66px" />
<input id="btnPrintForm" type="button" value="Print" onclick="printMe();"
style="width: 66px" />
<input id="btnCloseForm" type="button" value="Close" onclick="window.close();"
style="width: 66px" />
</td>
</tr>
</table>
</td>
</tr>
</table>
<%--bordercolordark="Gray" bordercolorlight="White"--%>
<table border="1" >
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<table class="formTbl" border="0" cellspacing="2px">
<colgroup>
<col width="75px" />
<col width="75px" />
<col width="50px" />
<col width="60px" />
<col width="60px" />
<col width="125px" />
<col width="100px" />
</colgroup>
<tr>
<td class="top" align="center" colspan="7">Sanitary Pipes Cleaned</td>
</tr>
<tr class="grayBack" valign="bottom">
<td align="center">From MH</td>
<td align="center">To MH</td>
<td align="center">Basin</td>
<td align="right">Footage</td>
<td align="center">Size</td>
<td align="center">WorkType</td>
<td align="center">Times Jetted</td>
</tr>
<tr>
<td colspan="7">
<hr />
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:Label ID="From_MH" runat="server" Text='<%# Eval("UP_MH_NO")%>'></asp:Label>
</td>
<td align="center">
<asp:Label ID="To_MH" runat="server" Text='<%# Eval("DN_MH_NO")%>'></asp:Label>
</td>
<td align="center">
<asp:Label ID="Basin" runat="server" Text='<%# Eval("BASIN")%>'></asp:Label>
</td>
<td align="right">
<asp:Label ID="Asbuilt_Length" runat="server" Text='<%# Eval("ASBUILT_LENGTH")%>'></asp:Label>
</td>
<td align="right">
<asp:Label ID="Diameter" runat="server" Text='<%# Eval("DIAMETER")%>'></asp:Label>
</td>
<td align="center">
<asp:DropDownList ID="lstWorkType" runat="server"
AutoPostBack="True" width="125px">
<asp:ListItem Selected="True">Maintenance</asp:ListItem>
<asp:ListItem>Grease</asp:ListItem>
<asp:ListItem>Root Cutting</asp:ListItem>
<asp:ListItem>Televising</asp:ListItem>
<asp:ListItem>Trouble</asp:ListItem>
</asp:DropDownList>
</td>
<td align="center">
<asp:DropDownList ID="lstTimesJetted" runat="server"
AutoPostBack="True" width="50px"
OnSelectedIndexChanged="lstTimesJetted_SelectedIndexChanged">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr >
<td align="center">Comment:</td>
<td colspan="5">
<asp:TextBox ID="txtComment" runat="server" Width="370px"></asp:TextBox>
</td>
<td >
<asp:Label ID="PipeID" runat="server" Text='<%# Eval("MAIN_ID")%>' Visible="false" ></asp:Label>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr >
<td colspan="7">
<hr />
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDS_Technician" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [TechName], [TechID] FROM [Technician]WHERE NOT [TechID] IN(0) ORDER BY [TechName] ">
</asp:SqlDataSource>
</form>
</body>
</html>
Re: Repeater control and MaintainScrollPositionOnPostback
ah, ok, I see what might be happening.
The asp:ScriptManager is an "older" technology, which was replaced by the ajaxToolkit:ToolkitScriptManager. It could be that the sample that you are looking at is out of date.
If you don't put the ScriptManager in, and only use the ToolkitScriptManager, what happens?
Gary
Re: Repeater control and MaintainScrollPositionOnPostback
Quote:
Originally Posted by
gep13
ah, ok, I see what might be happening.
The asp:ScriptManager is an "older" technology, which was replaced by the ajaxToolkit:ToolkitScriptManager. It could be that the sample that you are looking at is out of date.
If you don't put the ScriptManager in, and only use the ToolkitScriptManager, what happens?
Gary
Ok, you must be like freaking Gandalf or something. I swear I haven't touched the thing since I posted yesterday and it was acting up then. So what happens when I test it now - it bloody well works! I guess that is the good news. The bad news it I have no idea what changed, but I can tell you what was not happening before that is happening now. And that is that the "OnSelectedIndexChanged" event wasn't triggering so that the summary calculation wasn't being executed properly, AKA CalculateFootage() in post #1.
Well it works now. Thanks a million for looking at this, and helping me out with whatever magic or rain dance you performed. :)
Re: Repeater control and MaintainScrollPositionOnPostback
Hello there,
Not a problem at all. I am happy to see that the magic rain dance that I performed earlier did indeed work as intended :p
On a side note, do you use any form of version control? This can help in situations when you don't know what has changed, if anything, as you can refer to the previous version of a file, or set of files.
Gary
P.S. Remember to mark your thread resolved :)
Re: Repeater control and MaintainScrollPositionOnPostback
Gary,
You asked me that question before, and I am very positive that I don't. If I have to do some major rework I'll create a new form, copy the code from the original aspx file and then exclude it from the project. I guess some might call that the id10t method of version control :) Any suggested reading on using version control?
Sierk
Re: [RESOLVED] Repeater control and MaintainScrollPositionOnPostback
Hello,
It really depends on your budget, and what you preferences are.
There are a number free version control system out there, such as Subversion, Git, Mercurial, etc, and if you are able to afford it, there are larger system like Team Foundation Server that includes version control.
If you are just starting out then I would suggest that you take a look at either Subversion or Mercurial. You will find lots of information about them on their respective web sites.
Gary
Re: [RESOLVED] Repeater control and MaintainScrollPositionOnPostback
Hello,
It really depends on your budget, and what you preferences are.
There are a number free version control system out there, such as Subversion, Git, Mercurial, etc, and if you are able to afford it, there are larger system like Team Foundation Server that includes version control.
If you are just starting out then I would suggest that you take a look at either Subversion or Mercurial. You will find lots of information about them on their respective web sites.
Gary