JavaScript / ASP.NET Question (This is a good one)

J

Jeff Voigt

I just need a few pointers from a few experts to help me finish this up.

In a nutshell I want to return the user to where they left off on a page
througout numerous postbacks. So far, and with little implementation I have
the following:

Public Class BasePage

Inherits System.Web.UI.Page



Private Sub BasePage_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' get out if this is not a post back

If Not Page.IsPostBack Then Return

' get the object name that caused a post back

Dim objectName As String = CType(Request.Form("__EVENTTARGET"),
String)

' get out if the name is nothing

If objectName Is Nothing Then Return

If objectName.Length = 0 Then Return

' register a script to scroll back to this location when returning

RegisterStartupScript("scroll", "<script
language=javascript>document.forms[0]." + objectName +
".scrollIntoView();</script>")

End Sub



End Class


This works great if the user selects a dropdown item when the dropdown has
it's AutoPostback property set to True. Since all of my web pages are
derived from the BasePage this will work beautifully. There is one problem
however in that the __EVENTTARGET will not always refer to the object that
caused the postback. I need this in order for the object.scrollIntoView
java script to fire off.

I've gotten numerous tips as to how I can change it. The one I like best is
to have some kind of hidden fields that track the top/left x/y coordinate of
the window and store that in some hidden fields so on a post back I can
retrieve the values and then call a window.ScrollTo( x,y ) function rather
than relying on the object that caused the post back.

My question now would be, what javascript can I use to constantly store and
x,y coordinate into some hidden fields? I know how to add controls to the
page and get values out. I just need to know if there is a way I can get
the x,y values back from the page on a post back via (storing them in hidden
fields) or something else (if anyone has a better idea).

If this does not make sense, or someone knows a better way to achieve this
please let me know. I would really appreciate the constructive criticism.

Thanks,
- J
 
J

John Saunders

Jeff, you might want to make your subject a bit more specific. I almost
didn't read your post until I recognized your name.

Something like "Trying to Replace SmartNavigation With Custom JavaScript"
might be more interesting to more readers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,476
Members
44,896
Latest member
PenniGowin

Latest Threads

Top