forum

Home / DeveloperSection / Forums / MenuItem call javascript function

MenuItem call javascript function

Anonymous User 2223 24-Mar-2015

Dynamically building menu items and need to call a javascript function from one of them. 

    function popWin(url) {
        var winHandle= window.open(url, '_blank', 'width=1000,height=700,resizable=yes,top=5,left=5,scrollbars=yes,status=yes');
    } 
 <asp:Menu ID="Menu1" runat="server" StaticDisplayLevels="8" RenderingMode="List" OnMenuItemClick="Menu1_MenuItemClick" CssClass="menu" Width="150px">
 </asp:Menu>

The code behind: 

        string url ="/somepage.aspx";
        MenuItem child= new MenuItem();
        child.Text ="Some Text";
        child.NavigateUrl = "javascript:popWin('" + url + "');";
        //child.NavigateUrl ="javascript:window.open('somepage.aspx');";
        Menu1.Items[1].ChildItems.Add(child);

Just having some trouble calling the javascript function.

The window.open will work but an extra page opens and I need more control over the window opening. 

The reason this needs to be done this way is there's an iFrame on the page that's loading different pages. The RegisterStartupScript was being used in the Menu1_MenuItemClick event but it was refreshing the source of the iFrame. 

Thanks for any suggestions.


Updated on 24-Mar-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By