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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

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

    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



    Jeff Voigt Guest

  2. Similar Questions and Discussions

    1. Xcart no good, support no good, need good shopping cart!!!
      I need a good quality php shopping cart to port to my site, allowing software downloads and book sales. Integrating ease is really important and...
  3. #2

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

    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.
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]


    John Saunders Guest

  4. #3

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

    I'll do that now :)

    "Jeff Voigt" <jeffrey.voigt@djj.state.fl.us> wrote in message
    news:#gcnlUeXDHA.1640@TK2MSFTNGP10.phx.gbl...
    > 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
    >
    >
    >

    Jeff Voigt Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139