Showing posts with label figure. Show all posts
Showing posts with label figure. Show all posts

Saturday, March 24, 2012

Waving the white flag..scroll position.

Hey guys,

I'm loosing my mind over here trying to figure this out. I'm hoping someone can help me out.

Problem:

I have a datalist with a pager in an update panel which is all in a content page. The scriptmanager is in the master page. When i click on the different page numbers the datalist changes page but the scroll position stays at the bottom of the page where the pager is. I'd like to reset that scroll position to the top of the update panel but im having no luck. I've googled and searched this forum for a good 4-5hrs with no luck. I've found plenty of potential solutions but nothing working. Even setting focus to a hidden control isnt working. My only constraint is that I only want to reset teh scroll position when I move pages. not when there are other types of postbacks.

I've tried this code (im placing it in my content page) but it doesnt do anything ... im not sure if i need something in my codebehind aswell...:

<scripttype="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(EndRequestHandler);

function EndRequestHandler()

{

prm._scrollPosition =null;

}

</script>

Thanks,

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

<pages smartNavigation="true"MaintainScrollPositionOnPostback="true"/>

Usually People loves to maintain the scroll postiion. But requirment is reverse, Here is the trick, create an script tag after the scriptmanager and put the following lines:

<script type="text/javascript">var prm = Sys.WebForms.PageRequestManager.getInstance();prm.add_beginRequest(beginRequest);function beginRequest(){ prm._scrollPosition = null;}</script> 

Let me know if this helpful to you


hi chetan,

Thanks for the reply but i've tried that code aswell and still nothing happens. My script manager is on my master page so i dont want every page to postback to the top of the page only certain pages. I've tried placing that code in my <content> page but nothing happens. Is there anything else i need to do?

Does anyone else have any suggestions? I've tried enabling and disabling MaintainScrollPositionOnPostBack but it doesnt seem to have any effect.

Thanks


In all the posts i checked the same code above was given but thatdidn't work for me at all. However i was able to solve this problem.

I used the EndRequestHandler instead of BeginRequest

I used window.ScrollTo(0,0) instead of the prm._scrollPosition = null <-- this was the main problem

In order to only scroll to 0,0 when my pager was clicked:

I used the IntializeRequest handler and i stored the args.get_postBackElement() in a var.

Then back in my EndRequestHandler i checked to see if that was equal my datalist's clientId.

To make this more flexible i wraped it in a usercontrol with a PBControlId property that i set within the pages i use the control on.

Hope this saves ppl time.

WCF AJAX Enabled Service and looping through Dictionary<string,string>

I hope someone can help me on this. I've tried every sample and cant seem to figure it out. I'm returning a Dictionary<string,string> from a WCF Service using Visual 2008 with .Net 3.5.

public Dictionary<string, string> RetrieveNavigationStylesLists()
{
Dicationary<string,string> data = null;

...

data = new Dictionary<string, string>();
data.Add("StyleID", styles[loop][0].ToString());
data.Add("Style", styles[loop][1].ToString());
data.Add("Default", styles[loop][2].ToString());

return data;

}

in my javascript i've tried the following:

...
// WCF Service is invoked an on success calls the function below

function onNavigationSuccess(args)
{
for(var data in args)
{
var key = data;
var keyValue = args[data];

}
}

But when i loop through the data i get only

loop 1:
key = 0
keyValue =
-key = "StyleID"
-value = "2"

loop 2:
key = 1
keyValue =
-key = "Style"
- value = "Page Title"

I cant seem to get the key name or the key value

If i look at args is contains the following data:

args = [0]
which has key="StyleID" and value="2"
[1]
which has key="Style" and value="Page Title"
[2]
which has key="Default" and value="False"

I've tried every sample that is available but cant seem to get it to work

Thanks




check this hope it helpshttp://wiki.freaks-unidos.net/javascript-libraries