MaintainScrollPositionOnPostback

Mr_Shaw
Mr_Shaw used Ask the Experts™
on
is there a way in which I can reed what value is beening stored by maintainScrollPositionOnPostback.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
amx

Commented:
how about this:
Page.MaintainScrollPositionOnPostBack

Open in new window

Author

Commented:
I tried that suggestion

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

it returns TRUE not the vlaue of the scrollposition.
amx

Commented:
Tthe value is meant to either true or false.

what kind of value were you expecting?
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
numeric.

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

Author

Commented:
somewhere with the session the value must be store in order to maintain the scroll position. The question my friend is where?
amx

Commented:
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
amx

Commented:
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

Author

Commented:
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" />
amx

Commented:

Request["__SCROLLPOSITIONX"]

Open in new window

Author

Commented:
thanks

i tried

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

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

amx

Commented:
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

amx

Commented:
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

Author

Commented:
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
Commented:
try using __SCROLLPOSITIONY instead , it seems to be the only value which changes

Author

Commented:
thanks all works

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial