Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PostBack Pop Back?

Status
Not open for further replies.

abds

Programmer
Dec 13, 2000
46
0
0
US
When my users scroll down to the bottom of my page and push a button there, the PostBack pops them back into my page at the top. They then have to scroll back down.

Is there some way to get them back to where they were on the screen when they pressed the button?

TYIA
Phil

P.S. If I can't do this, I will settle for a way to automatically do a couple of Page Downs.
 
Have been having exactly the same problem myself. Have considered trying a anchor in the page but then how do you tell it to load the page with the #name attached to the URL. Surely this would cause the page to treat it as a new request not a postback and break the viewstate etc...

At the moment I am using two panels to display seperate controls and only showing half on the page at a time to avoid this...fortunately for me my app suits this approach - if it didnt, which most won't, this seems to me a fairly major limitation of providing a decent user experience with aspx....

very interested tohear any methods of dealing with this others have found.

Rob %-)

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
I posted on this earlier, but I may make an FAQ on it since it gets asked so much.

ASP.NET has something called "Smart Navigation". It maintains the users position on a page, as well as reduce flicker on postbacks.

To enable it, just add

SmartNavigation="True"

to your page directive (switch to html view of your page, and look for the line at the top that starts with <%@ ).

D'Arcy
 
A little look into this and I found you can set this for all pages in your app using the <pages> tag in web.config file, as well as other default values like enableviewstate. heres a link if anyone is interested


however have found what appears to be major limitation of this...it doesnt work for events fired from within a User Control.

On my current project I have nearly all form elements, buttons etc within user controls to allow reuse across the application and to keep things clean. Adding this SmartNaviagtion does nothign when the event is fired from within a user control!

Anyone know a way to replicate this for controls with the same lack of pain?

Rob

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
SmartNavigation works only with IE5 and up. Does anyone know how to make it work in Netscape?
 
Hey Rob,

Thanks very much for the link! Thats a great article, not just for the smart navigation part but for the other page directives that can be designated at the web.config level. Bravo!

As to your question though, I'm actually not sure why its not working for you. I just put together a dummy app:

a user control that writes out 1 to 100, and has a button that causes a postback to occur.

When I click the button though, I still maintain my location on the page (the user control is the only &quot;control&quot; on the page per se).

So maybe its something to do with multiple user controls on one page? Do you have any user controls that set focus to itself or soemthing, which might be overriding the smart navigation?

jn03: Netscape? Does ANYTHING work with Netscape? ;)

D'Arcy
 
Oooooo....fyi about setting the smart navigation at anything higher than a page level: you may notice things breaking in your application.

I have a page with a button on it. When you click the button, some javascript opens a new window with a calendar control. They select the date in that form, which closes the form and fills in a textbox on my main form with the date created.

When I had the smart navigation set at the web.config level though, not only did my calendar form render BEHIND my main form, but the functionality of selecting a date and filling hte text box was gone. I removed the directive in teh web.config and *poof* it was back working again.

So just FYI that Smart Nav might be better to set at the page level...or not; all depends on the application you're doing.

D'Arcy
 
I think your right D'Arcy, i do have multiple controls on the page and a lot going on to populate them with data - there is a great dela of interaction wired up between the controls at page level as well so I think the problem is focusing.

Thinking about the problem with the <pages > directive in web.config there are definitely situations where you wouldn't want this on because of the other functionality of smartnavigation such as the focused control retaining focus.

It may be easy if your app generally requires smart navigation to set it on at the application level in the web.config file and then off for indiviudal pages using the page directive...

Thanks for the thoughts on ascx - i'm going to have a play aroudn with it today and i'll let you know how i get on.

Rob

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
Hey, your post brought an idea up:

If keeping focus to a control is the only desired functionality, in the past (there's a post on here somewhere about it) I've done a function that take a control as a parameter and outputs javascript to the page to set the focus to that control on the postback.

It would stand to reason that if the control was further down a long page where you had to scroll, if the focus was set the scroll position would stay constant as well, because if you gave a control focus you'd have to see it.

Something that might be of use anyway

D
 
D'Arcy,
That function you just mentioned sounds very useful. Please post it here if you can remember or reconstruct it.

Phil

-----------------------------
We are drowning in data,
but starving for information.
Me
-----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top