Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2009, 10:06 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default Maintain page position after postback

Wondering if any one has a good example for the issue below:

I have a table which displays sql results. Within each row i have an image hyperlink which allows me to open a hidden row directly below the record using a querystring.

In this row is a simple form which posts a value back to the page.

What i am having issues with is the ability to maintain the possition of the page after postback. By using a simple <a name="unique_name"> in the row i can get a blocky navigation to the row but as with <a> names it display the row at the top of the page.

Below is a mockup of the table with both the record row and hidden row:

Code:
<%
'Query Strings
QsRowID = Request.QueryString("rid")
%>
<%
'Retrieve form value
SelVal=Request.Form("SelVal")
%>
<html>
<head>
</head>
<body>
<div align="center">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="600" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
      
<%
'clear row id
RowID=""
'Create records loop
for a = 0 to 45
'Create Unique row id for example
If RowID = "" then
RowID = 1
else
RowID = RowID + 1
End If
%>
        
<tr>
<td width="600" height="40" valign="middle">Record Row! <a href="example.asp?rid=<%=RowID%>"> Display hidden row below - <%=RowID%></a></td>
</tr>
          
<%
'Show Hidden row
If Trim(RowID) = Trim(QsRowID) then
%>
<form name="form" method="post"  action="example.asp?rid=<%=RowID%>">
<tr>
<td height="40" valign="middle">
Hidden Row &nbsp;
<select name="SelVal">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" name="submit" value="submit">
&nbsp;
<%
If Len(SelVal)>0 then
Response.Write "You selected " & SelVal
End If
%>
</td>
</tr>
</form>
<%
End If
%>
          
<%Next%>          
</table></td>
</tr>
<tr>
<td height="560">&nbsp;</td>
</tr>
</table>
</div>
</body>
</html>
I have been looking at various javascript examples but have not got any to work as yet.

Below is an example of page location that i have not been able to adapt:

http://forums.asp.net/t/336101.aspx

Put before end your form (before </form> tag):



<input id="__SAVESCROLL" name="__SAVESCROLL" value="0" type="hidden" runat="server" />
<script type="text/javascript" src="SaveScroll.js"></script>


To the SaveScroll.js file put:



function saveScroll()
{
var sScroll;
if (document.documentElement && document.documentElement.scrollTop)
sScroll = document.documentElement.scrollTop;
else if (document.body)
sScroll = document.body.scrollTop;
else
{
sScroll = 0;
}
document.getElementById('__SAVESCROLL').value = sScroll;
}

function restoreScroll()
{
var sScroll = document.getElementById('__SAVESCROLL').value;
if (sScroll > 0)
{
if (document.documentElement && document.documentElement.scrollTop)
document.documentElement.scrollTop = sScroll;
else if (document.body)
{
if (window.navigator.appName == 'Netscape')
window.scroll(0, sScroll);
else
document.body.scrollTop = sScroll;
}
else
{
window.scroll(0, sScroll);
}
// here is setting absolute positioning panel, if you need, set correct ID and uncomment follow 2 lines (and add needed lines/setting for all your panels)
//if (document.getElementById('pnlNewItem') != null )
//document.getElementById('pnlNewItem').style.top = sScroll + 'px';
}
}

window.onload = restoreScroll;
window.onscroll = saveScroll;
window.onresize = saveScroll;



To the head section of page put this conditionally comment meta-tag for quick page transition(in IE6+ will create very smooth postback, in other will be ignored because they dont support transition or dont support 0.1 time to play transition)



<!--[if gte IE 6]><meta http-equiv="Page-Enter" content="BlendTrans(Duration=0.1)" /><![endif]-->
If anyone can point me in the right direction that would be superb.

Cheers

Aspless
 
Old November 29th, 2009, 09:35 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

Add a div tag to your page. and add the restoreScroll to it like this

<div id = "myDiv" runat = "server">
<script type="text/javascript">
restoreScroll();
</script>
</div>

when this div tag is loaded into the browser codes are executed.
 
Old December 1st, 2009, 06:17 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Thanks irProject,

This looks like a really simple solution.

I have attempted to integrate the Javascript into the above example but am getting 'Object expected'.

Still unsure how i can get the value to restoreScroll() ..

Any additional advice would be great.

Cheers

Aspless
 
Old December 1st, 2009, 07:48 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

you should put a hidden input in your page to store value of scroll
<input type="hidden" id="myHidden" />

and in your page write the code of restoreScroll function like this:

<div id = "myDiv" runat = "server">
<script type="text/javascript">
function restoreScroll()
{
// code goes here
}
// call function
restoreScroll();
</script>
</div>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Panel - Maintain Screen Position dvance BOOK: Beginning ASP.NET 2.0 AJAX ISBN: 978-0-470-11283-0 0 July 3rd, 2008 05:20 PM
How to maintain history of last ten visited page i vishnu108mishra ASP.NET 2.0 Professional 1 February 29th, 2008 01:27 PM
Maintaining scroll position on postback majorpayne27 Struts 0 July 10th, 2007 09:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.