How to scroll long page to the label with error message?

D

Dmitry Duginov

I have the same panel with a label on multiple masterpages. That
(white-on-red) label text can contain some error messages if exceptions
occured in business layer after the user hit "Update" button.

I cannot find a way to scroll potentially long page making that text clearly
visible and get user attention. Page.SetFocus and WebControl.Focus do not
work with panels and labels and by default PostBack shows the top of the
page to the user, while errormessage can be on the bottom or somewhere in
the middle (depending on exact page layout and content).

Any ideas?

Dmitry
 
G

Guest

I have the same panel with a label on multiple masterpages. That
(white-on-red) label text can contain some error messages if exceptions
occured in business layer after the user hit "Update" button.

I cannot find a way to scroll potentially long page making that text clearly
visible and get user attention. Page.SetFocus and WebControl.Focus do not
work with panels and labels and by default PostBack shows the top of the
page to the user, while errormessage can be on the bottom or somewhere in
the middle (depending on exact page layout and content).

Any ideas?

Dmitry

Try to use scrollIntoView() method
http://msdn2.microsoft.com/en-us/library/ms536730.aspx

Example:

<script type="text/javascript">
var el = document.getElementById('h1');
if (el!=null)
el.scrollIntoView(true);
</script>

or add an alert() box that will be shown on top of all other content
 
D

Dmitry Duginov

Anon User said:
Try to use scrollIntoView() method
http://msdn2.microsoft.com/en-us/library/ms536730.aspx

Example:

<script type="text/javascript">
var el = document.getElementById('h1');
if (el!=null)
el.scrollIntoView(true);
</script>

or add an alert() box that will be shown on top of all other content

Thanks, it was helpful. However scrollIntoView works only in IE. Is there a
way to determine if the browser supports this method? If so, for those rare
cases when the user works from non-IE browsers I could throw alert('There
were some errors. See details at the bottom').

Regards,
Dmitry
 
G

Guest

Thanks, it was helpful. However scrollIntoView works only in IE. Is there a
way to determine if the browser supports this method? If so, for those rare
cases when the user works from non-IE browsers I could throw alert('There
were some errors. See details at the bottom').

Regards,
Dmitry- Hide quoted text -

- Show quoted text -

As far as I know it should work in IE and FF.

To detect client's browser you can use something like this:

if(navigator.userAgent.indexOf("Firefox")!=-1 ||
navigator.appVersion.indexOf("MSIE")!=-1){
el.scrollIntoView(true);
} else {
alert('Please review your form');
}
 
D

Dmitry Duginov

Anon User said:
As far as I know it should work in IE and FF.

Well, you are right. Kind of :)

scrollIntoView(true) works correctly in both browsers - object is shown and
aligned with the top of the page
scrollIntoView(false) does not really show the object if FireFox. It scrolls
the page the way that the previous object is aligned with the bottom of
browser area.

So, I end up with the following:

<script type="text/javascript">
var lblerrormessage = document.getElementById('ctl00_lblErrorMessage');
if (lblerrormessage!=null)
{
var not_IE = navigator.appVersion.indexOf("MSIE")==-1;
lblerrormessage.scrollIntoView(not_IE);
}
</script>

In IE error message would appear in the bottom (as desired), in FF - on the
top of the screen. But at least in both cases it will be visible...

Spasibo anyway, :)
Dmitry
 
G

Guest

Well, you are right. Kind of :)

scrollIntoView(true) works correctly in both browsers - object is shown and
aligned with the top of the page
scrollIntoView(false) does not really show the object if FireFox. It scrolls
the page the way that the previous object is aligned with the bottom of
browser area.

So, I end up with the following:

<script type="text/javascript">
var lblerrormessage = document.getElementById('ctl00_lblErrorMessage');
if (lblerrormessage!=null)
{
var not_IE = navigator.appVersion.indexOf("MSIE")==-1;
lblerrormessage.scrollIntoView(not_IE);
}
</script>

In IE error message would appear in the bottom (as desired), in FF - on the
top of the screen. But at least in both cases it will be visible...

Spasibo anyway, :)
Dmitry





- Show quoted text -- Hide quoted text -

- Show quoted text -

da no problem
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top