Unwanted Refresh/Redraw

K

Kevin Chandler

I appologize in advance if this is a novice question. I don't have much
ASP.Net experience.

I have an NCAA tournment selection page that I use asp:button controls. The
problem is that everytime I click one of the buttons, the entire page
redraws and the screen is scrolled to the top. How can I stop the entire
screen from refreshing or how can I stop the page from scrolling back up to
the top?

Thanks in advance for your help,
 
M

Marina

When you click on a button, that is the default behavior.You can stop the
postback with client side javascript if you don't want it to post back - but
typically people want it to post to the server to do some work.

There is not much you can do about the redrawing - the page posts to the
server, and then sends down a brand new page, which has to be downloaded and
drawn. This is the nature of web programming.

You can try turning on smart navigation on your page. That should fix the
scrolling issue. However, smart navigation is known to be buggy and can
sometimes cause problems, so be careful.
 
C

Charlie Nilsson [MSFT]

Another way to do this is to cheat a bit... You can use javascript in
the <body> tag's "onload" attribute. This attribute can be used to tell a
browser to seek an anchor on your page.

So, the idea is to place anchor tags next to each of your asp:button(s).
"<a name='buttonX' />" Or at least space anchors out on your webpage,
and label them descriptively.

Your asp logic can modidy the <body> element's onload attribute to force
the browser to navigate to a specific anchor tag immediately on page load.

For example, if someone clicked asp:button #2, you should have already
placed an anchor in the page near that button, like <a name='button2' />
When you 'build' the page on the server, make sure you insert the "onload"
attribute to the <body> tag. This would look something like
<body onload="javascript:window.location='#button2'">

That's probably not quite the right syntax, but you can search online for
good examples on javascript sites.



-Charlie
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top