asp.net scrolling

V

venky

I have a question. In asp.net page, how do u scroll to particular
position in a page. I have a button at the end of my page, when i click
the button, i do some validation and if the validation fails, i want to
scroll to particular postition in the page. Instead the page stays in
the same place where the button is.


any idea or inputs on scrolling?
 
S

SA

Because scrolling is a client-side function, you will need to implement this
client-side using a combination of JavaScript and anchor tags.

Then, you will need to figure out which control didn't pass the validation
and call your JavaScript function with a parameter that will position the
page at the right place.

This is a brief, untested example

<script language="JavaScript">
function navToLocal(anchorName)
{
// JavaScript code here to navigate to the anchor tag with the
specified name.
}
</script>

<a name="SomeName"></a><asp:TextBox runat="server"...></asp:TextBox>

<script language="vb" runat="server">
' Find out which control didn't validate and which anchor tag
' that control corresponds to.
' On page load, set an onload attribute on the body that will
' correctly call the navToLocal function.
</script>


Can't write most of the code of the top of my head, but I am sure Google
search will reveal most of what you need.

HTH
 
M

Mark Rae

I have a question. In asp.net page, how do u scroll to particular
position in a page. I have a button at the end of my page, when i click
the button, i do some validation and if the validation fails, i want to
scroll to particular postition in the page. Instead the page stays in
the same place where the button is.

Is your intended goal simply to show the user where the validation has
failed? In which case, I would *strongly* suggest you set focus to the field
which has failed validation by using the JavaScript focus() method. If the
field is currently off the edge of the screen, this will cause the page to
scroll automatically for you so that the field is visible.
 
P

Peter Blum

Microsoft's validation controls are not really designed for client-side
expandability. For example, if you took the suggestion of setting focus to a
field with the error, how would you write code that finds the first field
with the error and connect it up to Microsoft's scripts that fire when the
button is pressed. You will do some creative hacking to figure it out.

I want to let you know about an alternative that solves this. I rewrite
ASP.NET validation in "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx). It has 22 validators, support for
validation groups, and support for many more browsers in client-side
validation, like Mozilla, Opera 7 and Safari.

I listened to developers who were asking for many enhancements to ASP.NET
and addressed their needs. In your case, you will find these features:
1. There is an option to have it set focus to the first field with the error
upon submit or after you change a field. It can also change the style of
fields with errors, blink the error message, and put up an alert.
2. My ValidationSummary control can offer hyperlinks on its error messages.
When you click on a hyperlink, it jumps to the field with that error.
3. My ValidationSummary control has a setting that makes the page scroll to
show it when you click submit.

I include a utility to quickly switch a page from Microsoft's to my
validators.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top