Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2008, 06:23 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default Why does page scroll to top?

Hi Everyone,

I would like to thank all those who have been a help to me when I get stumped. Well here is my problem. I have a calendar control on my page located at the bottom. My question is why is it that when I run this page in the browser and then click on the calendar control the page scrolls up to the top where you then cannot see the calendar control? My second question is in the code behind files the class is called a partial class, why is it a partial class and not just a regular class? If my questions are elementary I apologize. If anyone can point me to the right direction I would appreciate that also.

Thanks Everyone



 
Old July 27th, 2008, 06:46 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you click a control that generates a postback, you are generating a page refresh. This results in a fresh re-render of the page from the top down, which naturally starts at the top. If you use the AJAX extensions you can make the calendar control refresh inside of an update panel which will eliminate the whole page refresh and result in much faster response from the calendar control.

Regarding the "partial class" issue. This is a little misleading. In the sense of actual objects/classes being created, there is no such thing as a "partial" class. It has to do with the way that code can be compiled. In the past, you had to define everything that makes up a code entity (i.e., structure, class, etc) in a single file. This became a burden for situations where one may want some part of the code to be auto generated by some tool. Partial classes now permit us to define multiple parts of the same class in different code blocks. I have intentionally avoided using the work "file" here because it's not technically about files. You could have a single file that contained something like this:
Code:
public partial class Foo{
   // some stuf here ...
}
public partial class Foo{
   // some more stuff here
}
While this is technically possible it doesn't make much sense as you could just put everything in the same file.

However, this makes a lot of sense when you want to break up the "concerns" of a class. In .NET development using Visual Studio the IDE creates a partial class file that contains all the stuff the designer takes care of (i.e. definition [and layout] for forms, both windows and ASP.NET). All the code that we manage is in another file. This keeps "our" file clean. In .NET 3.5 LinqToSQL a big file is generated with many partial classes for all the SQL database objects that are wired up to the data context. Defining them as partial in this file that VS manages allows us to add to the objects in our own files and not loose that work when the "VS file" is regenerated.

The partial class feature is very powerful, but you have to be careful where you use it. If you start breaking up your classes into too many files you can get into maintenance confusion. More importantly, feeling that you need to break up the file may indicate a bigger problem with class design. A refactoring may be in order to clean up the class(es).

-Peter
compiledthoughts.com
 
Old July 28th, 2008, 12:11 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I would only like to comment that there *ARE* ways to keep the cursor at or near the same location on the page, even when you do a postback.

In the <FORM>'s onsubmit handler (or in the appropriate handler of whatever control is forcing the form submit), you can use JavaScript to find where the page is scrolled to. You store that information in a hidden form field and allow the postback.

Then, when the page is refreshed, you have your server-side code generate JavaScript at the bottom of the page that changes the scroll position to what it was before the postback.

Note that this isn't completely reliable. If in the process of creating the new page that is sent back to the browser you add content to the page above the scroll point, the new page JS code won't be aware of that. Even this can be mitigated by using anchor points, but now you have to wonder if it's worth the trouble.
 
Old July 28th, 2008, 08:42 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What Old Pedant has described has been a feature of ASP.NET since the beginning, known as "Smart Navigation". You can add the following to your @ Page directive:

SmartNavigation="true"

I omitted it in my original reply for several reasons:
- It doesn't work at all or well in non-I.E. browsers
- It is outdated
- Using partial page rendering with the AJAX extensions is much better supported across browsers, elegant and efficient.

-Peter
compiledthoughts.com
 
Old July 28th, 2008, 08:50 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

dotnetDeveloper -

Thanks for the personal email, although I would prefer that you post in the thread to keep the conversation coherent.

Regarding your question about AJAX: Visit http://www.asp.net/ajax/ for loads of information about the ASP.NET AJAX extensions. You can get the library there as well as many code samples and tutorials.

As to the other question: I learned this stuff by using it. It's my job. That as well as reading and experimenting.

-Peter
compiledthoughts.com
 
Old July 28th, 2008, 12:30 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 dotnetDeveloper -

Thanks for the personal email, although I would prefer that you post in the thread to keep the conversation coherent.

Regarding your question about AJAX: Visit http://www.asp.net/ajax/ for loads of information about the ASP.NET AJAX extensions. You can get the library there as well as many code samples and tutorials.

As to the other question: I learned this stuff by using it. It's my job. That as well as reading and experimenting.

-Peter
compiledthoughts.com
 
Old July 28th, 2008, 12:34 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default

Thanks for the personal email, although I would prefer that you post in the thread to keep the conversation coherent.

Regarding your question about AJAX: Visit http://www.asp.net/ajax/ for loads of information about the ASP.NET AJAX extensions. You can get the library there as well as many code samples and tutorials.

As to the other question: I learned this stuff by using it. It's my job. That as well as reading and experimenting.

-Peter
compiledthoughts.com
[/quote]



Hey Peter,
 Thank You for steering me in the right direction. I really do appreciate all your help. I was wondering how can I tell if the Ajax library of extensions is already installed on my computer?

 
Old July 28th, 2008, 01:57 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
quote:Originally posted by planoie
 What Old Pedant has described has been a feature of ASP.NET since the beginning, known as "Smart Navigation". You can add the following to your @ Page directive:

SmartNavigation="true"
Actually, I was suggesting "roll your own", for the very reason that the stuff ASP.NET does is indeed not well thought out for cross-browser compatibility. Or at least that was true in ASP.NET 1.1; haven't looked to see if they improved it at all in 2.0 or later.

But, yes, it's the same principle.

And I don't really disagree with you about there being better solutions, although I'm far from convinced that Ajax should be the one and only universal panacea. There *ARE* other solutions, but even though Ajax is clumsy and problematic in some scenarios, it seems to be the only thing that people try. Oh, well.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 15 p.774 at the top of page shade cat BOOK: Ivor Horton's Beginning Visual C++ 2005 0 June 5th, 2007 03:04 PM
Repositioning Top Left Corner of a Page in print dontknowmuch Java GUI 0 September 30th, 2005 12:05 PM
right side of page cuts off!need it to scroll? doll deluxe Dreamweaver (all versions) 6 August 28th, 2004 03:36 AM
question asked(bring flash page to the top) ExxWhyZee Flash (all versions) 1 April 13th, 2004 12:48 PM
Sync Top Frame with Web Page savoym HTML Code Clinic 1 January 20th, 2004 04:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.