MaintainScrollPositionOnPostback

is there a way in which I can reed what value is beening stored by maintainScrollPositionOnPostback.

Mr_ShawAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amxCommented:
how about this:
Page.MaintainScrollPositionOnPostBack

Open in new window

Mr_ShawAuthor Commented:
I tried that suggestion

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

it returns TRUE not the vlaue of the scrollposition.
amxCommented:
Tthe value is meant to either true or false.

what kind of value were you expecting?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Mr_ShawAuthor Commented:
numeric.

I have hoping to get the X or the Y scroll position
Mr_ShawAuthor Commented:
somewhere with the session the value must be store in order to maintain the scroll position. The question my friend is where?
amxCommented:
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
amxCommented:
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
Mr_ShawAuthor 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" />
amxCommented:

Request["__SCROLLPOSITIONX"]

Open in new window

Mr_ShawAuthor 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'.

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

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mr_ShawAuthor Commented:
thanks all works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.