Executing javascript from menu adapter RRS feed

  • Question

  • User377889045 posted

    Is there an easy way to execute a registered javascript from the menu adapter?<o:p> </o:p>

    I usually do this:

    In code behind: 

    HyperLink1.Attributes("onclick") = "popup_" & PopName & "();focus();" 

    Which creates this in the html: 

    <a id="HyperLink1" onclick="popup_myFeed();focus();" href="javascript:void(0)">

    Or do I need to alter the adapter source code?

     Any creative ideas before I alter the code?

    Thursday, November 15, 2007 2:27 PM

All replies

  • User377889045 posted

    The only adapter I have played with so for is the menu adapter, so changes were made there and not in “WebControlAdapterExtender.vb” as I am not certain of the impact it would have on other adapters.

    Made the following changes to MenuAdapter.vb in Sub routine BuildItem:

    If (IsLink(item)) Then
        If (Not String.IsNullOrEmpty(item.NavigateUrl)) Then
           ' Begin script exception code
            If (item.Target.StartsWith("javascript:")) Then
             writer.WriteAttribute("href", Page.Server.HtmlEncode(menu.ResolveClientUrl(item.Target)))
                item.Target = Nothing
                Dim js As String = item.NavigateUrl.ToString
                writer.WriteAttribute("onclick", js)
                writer.WriteAttribute("onkeypress", js)
                ' End script exception code
                writer.WriteAttribute("href", Page.Server.HtmlEncode(menu.ResolveClientUrl(item.NavigateUrl)))
          End If


    In code behind:

    ' Set variable script popup name from PopName property in
    ' class instance and add hyperlink attributes
    strPopUp = "popup_" & myPopup.PopName & "();focus();"
    HyperLink1.Attributes("onclick") = strPopUp
    HyperLink1.Attributes("href") = "javascript:void(0)"

    ' Set Menu adapter variables for specific menu item
    Me.Menu1.Items(0).ChildItems(0).ChildItems(0).Target = "javascript:void(0);"
    Me.Menu1.Items(0).ChildItems(0).ChildItems(0).NavigateUrl = strPopUp

    Friday, November 16, 2007 7:21 AM