Function to Navigate To Named Anchor

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;

    }