473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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=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("BookMa rkScript")) 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
Jun 27 '08 #1
2 2459
"Keith G Hicks" <kr*@comcast.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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 <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 RegisterStartUpScript 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='#BottomOfPage';")
Script.Append("if(location.hash!=hashValue)")
Script.Append("location.hash=hashValue;")

If (Not ClientScript.IsClientScriptBlockRegistered("BookMa rkScript")) Then
ClientScript.RegisterStartUpScript (GetType(), "BookMarkScript",
Script.ToString(), True)
End If
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2
Thanks Mark. That did it. I also had to removee the # from the <a
name="#BottomOfPage"></a>
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:#E**************@TK2MSFTNGP03.phx.gbl...
"Keith G Hicks" <kr*@comcast.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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 <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 RegisterStartUpScript 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='#BottomOfPage';")
Script.Append("if(location.hash!=hashValue)")
Script.Append("location.hash=hashValue;")

If (Not ClientScript.IsClientScriptBlockRegistered("BookMa rkScript")) Then
ClientScript.RegisterStartUpScript (GetType(), "BookMarkScript",
Script.ToString(), True)
End If
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan M | last post by:
Is there anyway to return to a specific location on a web page after a postback? If I place a list box at the bottom of a web page that a user has to scroll to, how can I allow them to add items...
8
by: moondaddy | last post by:
Is there a way to make the browser move back to the previous page via code behind on the server? The effect would be the same as the user clicking on the browser's back button. Thanks. --...
6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
5
by: Mr Newbie | last post by:
OK, I have a fairly simple setup where I have an Index of records which are displayed using a datagrid on a page. When you click the link associated with a Row (ArticleID) , this ID is passed to a...
3
by: MattB | last post by:
I have an asp.net 1.1 eCommerce application that has a product page where the user can select from many different options that affect the price of the main product. I've implemented this with...
4
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link...
3
by: =?Utf-8?B?bWF2cmlja18xMDE=?= | last post by:
Hi, I have a page and if a user posts back data the page would open at the top. This is not a problem if the user was looking at the content on the top of the page , but if the page is long and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.