Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

move back to bottom of page after postback

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith G Hicks - 15 Apr 2008 04:44 GMT
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=JavaScript id='BookMarkScript'>
")
           Script.Append("var hashValue='#BottomOfPage'; ")
           Script.Append("if(location.hash!=hashValue) ")
           Script.Append("location.hash=hashValue; ")
           Script.Append("</script>")

           If (Not
ClientScript.IsClientScriptBlockRegistered("BookMarkScript")) Then
               ClientScript.RegisterClientScriptBlock(Me.GetType,
"BookMarkScript", Script.ToString())
           End If

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

<a name="#BottomOfPage"></a>

Can anyone tell me what I'm doing wrong?

Thanks,

Keith
Mark Rae [MVP] - 15 Apr 2008 14:13 GMT
> Can anyone tell me what I'm doing wrong?

You're using RegisterClientScriptBlock.

This places the JavaScript at the beginning of the webform i.e. just after
the opening <form> tag. 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 RegisterStartUpScript instead, as this places the JavaScript at the end
of the webform i.e. just before the closing </form> tag.

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

Dim Script As New StringBuilder()
Script.Append("var hashValue='#BottomOfPage';")
Script.Append("if(location.hash!=hashValue)")
Script.Append("location.hash=hashValue;")

If (Not ClientScript.IsClientScriptBlockRegistered("BookMarkScript")) Then
   ClientScript.RegisterStartUpScript (GetType(), "BookMarkScript",
Script.ToString(), True)
End If

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Keith G Hicks - 15 Apr 2008 14:48 GMT
Thanks Mark. That did it. I also had to removee the # from the <a
name="#BottomOfPage"></a>

> > Can anyone tell me what I'm doing wrong?
>
[quoted text clipped - 25 lines]
> ASP.NET MVP
> http://www.markrae.net

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.