Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

Below is  a helper function to insert javascript  to Navigate To Named Anchor

Page should have anchor with the passed name

<a name="anchorName"></a>

   

    // from http://www.webdeveloper.com/forum/showthread.php?threadid=112603

    ///<summary>///

    ///</summary>

    ///<param name="page"></param>

    ///<param name="anchorName"></param>

    ///<remarks>Page should have anchor with the passed name <a name="anchorName"></a>

    /// If there are more than one call on the page, first one will take preference

    ///</remarks>

    public static void NavigateToNamedAnchor(Page page, string anchorName)

    {

        String script = String.Format("window.location.hash = '{0}';", anchorName);

        //NOTE: if there are more than one call on the page, first one will take preference

        //If we want that last will take preference, change key from MethodBase.GetCurrentMethod().Name to anchorName

        page.ClientScript.RegisterStartupScript(TypeForClientScript(), MethodBase.GetCurrentMethod().Name, script, true);

        //return script;

    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted on Wednesday, May 14, 2008 2:28 PM ASP.NET | Back to top


Comments on this post: Function to Navigate To Named Anchor

# re: Function to Navigate To Named Anchor
Requesting Gravatar...
Nice post,

"if there are more than one call on the page, first one will take preference"why should it be like that?

Anyway, thanks for the post
Left by web development company on Aug 18, 2009 2:29 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net