move back to bottom of page after postback

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith G Hicks

    move back to bottom of page after postback

    I have a fairly long page with a submit button, a validation summary and a
    status label at the bottom of the page. I need it to go back to the bottom
    after the post so that the user can see any status information.

    I found some code that is supposed to do this but I cannot get it to work.
    it compiles and runs but does not move me down to the bottom fo the page.
    Here's my VB code that runs at the end of a sub where I post data back to
    the database:

    Dim Script As New StringBuilder()
    Script.Append(" <script language=JavaSc ript id='BookMarkScr ipt'>
    ")
    Script.Append(" var hashValue='#Bot tomOfPage'; ")
    Script.Append(" if(location.has h!=hashValue) ")
    Script.Append(" location.hash=h ashValue; ")
    Script.Append(" </script>")

    If (Not
    ClientScript.Is ClientScriptBlo ckRegistered("B ookMarkScript") ) Then
    ClientScript.Re gisterClientScr iptBlock(Me.Get Type,
    "BookMarkScript ", Script.ToString ())
    End If

    Here's the anchor that is near the bottom of the page:

    <a name="#BottomOf Page"></a>


    Can anyone tell me what I'm doing wrong?

    Thanks,

    Keith


  • Mark Rae [MVP]

    #2
    Re: move back to bottom of page after postback

    "Keith G Hicks" <krh@comcast.ne twrote in message
    news:%23GQGbrqn IHA.4208@TK2MSF TNGP02.phx.gbl. ..
    Can anyone tell me what I'm doing wrong?
    You're using RegisterClientS criptBlock.

    This places the JavaScript at the beginning of the webform i.e. just after
    the opening <formtag. This means that (almost certainly) the rest of the
    form including the anchor tag hasn't been created when the script tries to
    run.

    Use RegisterStartUp Script instead, as this places the JavaScript at the end
    of the webform i.e. just before the closing </formtag.

    Also, there's no need to include the <scriptand </scripttags explicitly,
    as ASP.NET will do this for you, e.g.

    Dim Script As New StringBuilder()
    Script.Append(" var hashValue='#Bot tomOfPage';")
    Script.Append(" if(location.has h!=hashValue)")
    Script.Append(" location.hash=h ashValue;")

    If (Not ClientScript.Is ClientScriptBlo ckRegistered("B ookMarkScript") ) Then
    ClientScript.Re gisterStartUpSc ript (GetType(), "BookMarkScript ",
    Script.ToString (), True)
    End If


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Keith G Hicks

      #3
      Re: move back to bottom of page after postback

      Thanks Mark. That did it. I also had to removee the # from the <a
      name="#BottomOf Page"></a>


      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:#EvhPqvnIH A.3512@TK2MSFTN GP03.phx.gbl...
      "Keith G Hicks" <krh@comcast.ne twrote in message
      news:%23GQGbrqn IHA.4208@TK2MSF TNGP02.phx.gbl. ..
      >
      Can anyone tell me what I'm doing wrong?
      >
      You're using RegisterClientS criptBlock.
      >
      This places the JavaScript at the beginning of the webform i.e. just after
      the opening <formtag. This means that (almost certainly) the rest of the
      form including the anchor tag hasn't been created when the script tries to
      run.
      >
      Use RegisterStartUp Script instead, as this places the JavaScript at the
      end
      of the webform i.e. just before the closing </formtag.
      >
      Also, there's no need to include the <scriptand </scripttags
      explicitly,
      as ASP.NET will do this for you, e.g.
      >
      Dim Script As New StringBuilder()
      Script.Append(" var hashValue='#Bot tomOfPage';")
      Script.Append(" if(location.has h!=hashValue)")
      Script.Append(" location.hash=h ashValue;")
      >
      If (Not ClientScript.Is ClientScriptBlo ckRegistered("B ookMarkScript") ) Then
      ClientScript.Re gisterStartUpSc ript (GetType(), "BookMarkScript ",
      Script.ToString (), True)
      End If
      >
      >
      --
      Mark Rae
      ASP.NET MVP

      >

      Comment

      Working...