?
Solved

MaintainScrollPositionOnPostback

Posted on 2008-11-19
15
Medium Priority
?
402 Views
Last Modified: 2013-12-17
is there a way in which I can reed what value is beening stored by maintainScrollPositionOnPostback.

0
Comment
Question by:Mr_Shaw
  • 8
  • 7
15 Comments
 
LVL 9

Expert Comment

by:amx
ID: 22993335
how about this:
Page.MaintainScrollPositionOnPostBack

Open in new window

0
 

Author Comment

by:Mr_Shaw
ID: 22993344
I tried that suggestion

Response.Write(Page.MaintainScrollPositionOnPostBack.ToString());

it returns TRUE not the vlaue of the scrollposition.
0
 
LVL 9

Expert Comment

by:amx
ID: 22993357
Tthe value is meant to either true or false.

what kind of value were you expecting?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Mr_Shaw
ID: 22993388
numeric.

I have hoping to get the X or the Y scroll position
0
 

Author Comment

by:Mr_Shaw
ID: 22993394
somewhere with the session the value must be store in order to maintain the scroll position. The question my friend is where?
0
 
LVL 9

Expert Comment

by:amx
ID: 22993415
I found this:

Javascript will be inserted into your rendered page that maintains the scroll position in the browser window for all post back.
Believe me it's really a good feature in ASP.net 2.0, it would reduce lots of coding effort to maintain scroll position in web page.

here:
http://riteshk.blogspot.com/2007/08/smartnavigation-vs-maintainscrollpositi.html
0
 
LVL 9

Expert Comment

by:amx
ID: 22993421
Even better, this should help you get the values, in seems there are hidden values in the form

http://aspnet.4guysfromrolla.com/articles/111407-1.aspx
0
 

Author Comment

by:Mr_Shaw
ID: 22993502
I am not the best at javascript. Do you know how to extract the value of the hidden textbox into a c# variable

<input type="hidden" name="__SCROLLPOSITIONX" id="__SCROLLPOSITIONX" value="0" />
0
 
LVL 9

Expert Comment

by:amx
ID: 22993531

Request["__SCROLLPOSITIONX"]

Open in new window

0
 

Author Comment

by:Mr_Shaw
ID: 22993570
thanks

i tried

 Response.Write(Request["__SCROLLPOSITIONX"].ToString());

but i got an error saying 'object reference not set to an instance of an object'.

0
 
LVL 9

Expert Comment

by:amx
ID: 22993605
yeah it won't have a value when the page first loads as the value hasn't been posted to the page, you can assume it will always be zero.

Its only after the first postback the value can be retrieved. What your code is doing is applying the .toString method when the value of the request is null.

Have a play around with the code i've written below, it should help you understand whats going on :)


string value = String.Empty;
        if (Request["__SCROLLPOSITIONX"] == null)
        {
            value = "nothing";
        }else
        {
            value = Request["__SCROLLPOSITIONX"];
        }
 
        Response.Write("__SCROLLPOSITIONX : " + value);

Open in new window

0
 
LVL 9

Expert Comment

by:amx
ID: 22993620
Once you understand the above you can use this, its the same code but condensed into two lines:
string value = Request["__SCROLLPOSITIONX"] ?? "boo";
Response.Write("__SCROLLPOSITIONX : " + value);

Open in new window

0
 

Author Comment

by:Mr_Shaw
ID: 22993728
I have tried using the code and in it should work, however my results are

__SCROLLPOSITIONX : 0

this happens every time i run the code
0
 
LVL 9

Accepted Solution

by:
amx earned 2000 total points
ID: 22993754
try using __SCROLLPOSITIONY instead , it seems to be the only value which changes
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31518176
thanks all works
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question