---
title: "MenuItem call javascript function"  
description: "MenuItem call javascript function"  
author: "Anonymous User"  
published: 2015-03-24  
updated: 2015-03-24  
canonical: https://www.mindstick.com/forum/23048/menuitem-call-javascript-function  
category: "javascript"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# MenuItem call javascript function

Dynamically [building](https://www.mindstick.com/blog/23088/which-tonewood-is-suitable-for-building-a-guitar) menu items and need to call a [javascript function](https://www.mindstick.com/forum/2090/send-data-from-asp-dot-net-code-behind-to-a-javascript-function) from [one of them](https://answers.mindstick.com/qa/47593/what-are-the-prevalent-water-proofing-systems-write-a-short-notes-on-any-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](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-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](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript).open will work but an extra page opens and I need more [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-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](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) but it was refreshing the [source](https://www.mindstick.com/interview/840/what-happens-if-the-both-source-and-destination-are-named-same) of the iFrame.

Thanks for any suggestions.

## Replies

### Reply by Anonymous User

After coming back to this problem and testing a span tag in html with an onclick event, the problem was simply a bit of syntax:

```
        child = new MenuItem();        string win ="/SomePage.aspx";        string script= "popWin('" + win + "');";        string text ="<span style=\"cursor:pointer;\" onclick=\"" +
script + "\">Some Text</span>";        //Below is how it should render        //<span style="cursor:pointer;"
onclick="popWin('/SomePage.aspx');">Some Text</span>        child.Text =text;       
child.Selectable = false;       
Menu1.Items[1].ChildItems.Add(child);
```

Thought I would post this just in case anyone else runs into the same issue.


---

Original Source: https://www.mindstick.com/forum/23048/menuitem-call-javascript-function

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
