LinkButton to post back, update UpdatePanel and jump to top of the page.

Last post 09-26-2008 7:18 AM by Matt Winward. 3 replies.

Sort Posts:

  • LinkButton to post back, update UpdatePanel and jump to top of the page.

    08-14-2008, 8:08 AM
    • Member
      348 point Member
    • Matt Winward
    • Member since 08-07-2008, 5:34 AM
    • UK
    • Posts 81

    Hello all.

    I've got an interesting predicament. The page is quite complex, but imagine this simplified layout...

    <Page>

    <UpdatePanel> Lots of content </UpdatePanel>

    <LinkButton/>

    </Page>

    Now when the LinkButton is clicked, it does a post back and updates whatever is inside the update panel by calling Update on it. So the page doesn't move, and only a portion of it redraws. The link button that was clicked needs to do its postback and update the update panel, but it needs to also jump the user to the top of the page.

    I managed at one point to get the jump happening, but then the post back didn't take place. I was wondering how people would tackle this one? Is there a best practice approach to this kind of thing?

     

    Thanks,

    Matt

    My code doesn't have bugs, it just develops random features.
  • Re: LinkButton to post back, update UpdatePanel and jump to top of the page.

    08-14-2008, 8:26 AM
    • Member
      712 point Member
    • TCavins
    • Member since 05-23-2007, 2:06 PM
    • Detroit, MI
    • Posts 186

    You could create a javascript function like the following:

     

    function pageLoad(sender, args)
    {
    	if(args.get_isPartialLoad())
    	{
              // set focus to a control at the top of your page
    	}
    
    }

    This may work, but would fire for all partial postbacks on your page.

    Tim

  • Re: LinkButton to post back, update UpdatePanel and jump to top of the page.

    08-14-2008, 10:10 AM
    • Member
      348 point Member
    • Matt Winward
    • Member since 08-07-2008, 5:34 AM
    • UK
    • Posts 81

    TCavins:

    You could create a javascript function like the following:

     

    function pageLoad(sender, args)
    {
    	if(args.get_isPartialLoad())
    	{
              // set focus to a control at the top of your page
    	}
    
    }

    This may work, but would fire for all partial postbacks on your page.

    Tim

     

    Thanks for that, Tim. Might be a handy fall back plan if there's way to only do it for that link button.

    It's unrelated, but I've now got a strange problem where the anchor tag I'm adding for focusing (for the above) isn't appearing in the resulting HTML at all. Other than that, it should work, as I can get it to focus other controls that are already on the page :)

    My code doesn't have bugs, it just develops random features.
  • Re: LinkButton to post back, update UpdatePanel and jump to top of the page.

    09-26-2008, 7:18 AM
    Answer
    • Member
      348 point Member
    • Matt Winward
    • Member since 08-07-2008, 5:34 AM
    • UK
    • Posts 81

    If anyone was curious, the solution to this was quite simple in the end. I just used the script manager to set focus on a control in the page. So my post back event (the click event for the link button) has the following kind of thing:

    scriptManager.SetFocus(control);

    My code doesn't have bugs, it just develops random features.
Page 1 of 1 (4 items)