How to scroll a web page?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I scroll a web page in code?

I need to send the user to a specific page location after a
SelectedIndexChanged RadioButtonList event.
 
The problem with this is that, after redirect, the form page loss all
controls values, is there other way?
 
Hi,

This require the use of javascript in the client and a little code in the
server side

What you do is include a <a> tag where you want to go and then in the
body's onload you change the location to it

The code below was extracted from a page that does it.

aspx code:
<script>
var gotomark = "";
function GotoMark()
{
if ( gotomark !='')
location = "#"+ gotomark;
//document.all[ gotomark].focus();
}
</script>
<body MS_POSITIONING="GridLayout" bottommargin=0 topmargin=0
onload="GotoMark();">

Now in the code behind you give the gotomark variable the value of the <a>
you included in the correct position , in my case it's a row in a datagrid


recordgrid.SelectedIndex = GetSelectedIndex();
//Now set an A element
LiteralControl tag = new LiteralControl("<a id='cometome'
name='cometome'>");

recordgrid.Items[ recordgrid.SelectedIndex].Cells[2].Controls.Add(
tag);
gotomark = new LiteralControl( "<script> var gotomark='';</script>" );
this.Controls.Add( gotomark);



This should solve your problem

Cheers,
 
Back
Top