Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repositioning within a div

Status
Not open for further replies.

liuk

Programmer
Jan 16, 2006
54
IT
Hi,

i have two div in my asp.net page and a datagrid in each one of them.

when i scroll a div and then edit an item the grid scroll back on top, so i must return to the selected item.
How can i make thi automatically with a script?

I tried this but it doesn't work :

function setCoordinates()
{
var myPageX;
var myPageY;
if (document.all)
{
myPageX = document.body.scrollLeft;
myPageY = document.body.scrollTop;
}
else
{
myPageX = window.pageXOffset;
myPageY = window.pageYOffset;
}

document.getElementById('PosX').value = myPageX;
document.getElementById('PosY').value = myPageY;

}


function SmartNav()
{
window.scrollTo(document.getElementById('PosX').value, document.getElementById('PosY').value);
}

and set

body.onscroll = setCoordinates
div.onscroll = setCoordinates
body.onload = SmartNav


Any suggest?
thanks
 
Just keep track of the id of the item that was last edited and use the scrollIntoView method upon reload to return to that tag.

Code:
document.getElementById("theIdOfTheTagWeWereLastModifying").scrollIntoView()

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 

I tried to write this code too :

VB :

Private Sub DG1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DG1.ItemDataBound

If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then

CType(e.Item.FindControl("btnEdit"),ImageButton).Attributes.Add("onclick", "SaveObjID(this.id)") '<--- Save the button's ID on click

CType(e.Item.FindControl("btnDelete"),ImageButton).Attributes.Add("onclick", "SaveObjID(this.id)") '<--- Save the button's ID on click
End If
End Sub


Script:

function SaveObjID(OBJID)
{
document.getElementById('ObjectID').value = OBJID;
}

function Scroll(){
document.getElementById(document.getElementById('ObjectID').value).scrollIntoView();
}

Then on the body.onload event invoke the Scroll function

It doesn't work, even if the hidden field ObjectID is written correctly when the Scroll function is called.
The strange is if i write the object id directly in the hidden field (i.e. document.getElementById('ObjectID').value='ucMyEditGrid_DG1__ctl4_btnEdit' ) it works!!!!




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top