Single button scrollTo (or location.hash)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redarko
    New Member
    • Mar 2008
    • 2

    #1

    Single button scrollTo (or location.hash)

    I have a set of imageButtons in my repeater that is in an update panel control.

    I would like to scroll up the page when the user clicks on one of these image (only in this case).

    I have tried three solution:

    1)Using the add_endRequest( EndRequestHandl er);function EndRequestHandl er as above but that cause every button in the page to scroll up the page.

    Code:
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript' language='javascript'>Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);function EndRequestHandler(sender, args){scrollTo(0,0);}</script>", false);

    2)Calling a function in my js file cause the page scrolling up and then suddenly scroll down to the same postion again
    Code:
    ScriptManager.RegisterStartupScript(e.Item.FindControl("imgPhoto"), e.Item.FindControl("imgPhoto").GetType(), "temp", "<script type='text/javascript' language='javascript'>Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);function EndRequestHandler(sender, args){scrollTo(0,0);}</script>", false);
    3)Redirecting to an anchor.

    This doesn't updates my ajax panels in the page, even if I execute the conditional update.
    Code:
    Response.Redirect(Vote.aspx#ScrollTop);

    Do you know how I can do that?

    I write the asp.net and the .js code below

    Code:
    <asp:UpdatePanel ID="pnlRepeater" runat="server" UpdateMode="conditional">
    		<ContentTemplate>
    		<div class="view_row">
    		<asp:Label ID="lblSearchResult" runat="server" Visible="false" />
    		<asp:Repeater ID="rtp_AlbumPhotos" OnItemDataBound="rtp_AlbumPhotos_OnItemDataBound"
                            OnItemCommand="rtp_AlbumPhotos_ItemCommand" runat="server">
                <ItemTemplate>
                    <div class="view_row_picture-holder">
                        <div>
                            <table>
                                <tr>
                                    <td id="selectPic" valign="bottom" runat="Server">
                                        <asp:ImageButton ID="imgPhoto" CommandArgument="PhotoSelect" runat="server" CssClass="view_row_img" OnClick="test_click"/>
                                        <br />
                                         <asp:Label ID="lblPicName" CssClass="view_row_item_text" runat="server"></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="clear">
                        </div>
                       
                        <br />
                        <asp:Label ID="lblPicLocation" Visible="false" CssClass="view_row_item_text" runat="server"></asp:Label>
                        <asp:TextBox ID="hdnAlbumPhotoId" Visible="false" Width="13" runat="server"></asp:TextBox>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
    		</div>
    			    <div class="clearer"></div>	
    	    <asp:Panel ID="pnl_AlbumPhotosNav" runat="server">
    		<div class="row_buttons">
    			<asp:ImageButton ID="btnPrev" runat="server" ImageUrl="images/home/btn_previous16.gif" AlternateText="Previous" OnClick="btnPrevious_AlbumPhoto_Click" CssClass="left" />
    			<asp:ImageButton ID="btnNext" runat="server" ImageUrl="images/home/btn_next16.gif" AlternateText="Next" OnClick="btnNext_AlbumPhoto_Click" CssClass="right" />
    			<div class="clearer"></div>
    		</div>	
    		</asp:Panel>
    		</ContentTemplate>
    		</asp:UpdatePanel>

    Code:
    function scroll()
    {
        scrollTo(0,50);
    }
  • redarko
    New Member
    • Mar 2008
    • 2

    #2
    I've just solved it.

    I was thinking a too much complicated solution.

    If I iterate on the page load in all the elements of my repeater and I set
    Code:
    ((System.Web.UI.WebControls.ImageButton)(dItem.FindControl("imgPhoto"))).Attributes.Add("onClick", "scrollTo(0,50);");
    it works perfectly

    Comment

    Working...