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;

    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ Wednesday, May 14, 2008 2:28 PM

Print

Comments on this entry:

# re: Function to Navigate To Named Anchor

Left by web development company at 8/18/2009 2:29 AM
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

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345