SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an webpart running on SharePoint 2010 which displays a grid of items using a SharePoint:SPGridView control. The first çolumn should display a typical SharePoint menu with the possible actions for the item and the column value it self should be a link to the "View" page.

The default SharePoint behavior is that the "View" page opens up on a modal, and I'd like my grid to behave the same way, so I must use the SharePoint:SPMenuField control.

The problem is it appears that SPMenuField.NavigateUrlFormat property does not support javascript in it, so I cannot get the page to open on the modal.

The code:

<SharePoint:SPGridView runat="server" ID="ResultsGrid" 
<EmptyDataRowStyle  />
    <SharePoint:SPMenuField HeaderText="Title" TextFields="Name" MenuTemplateId="ActionsMenu" NavigateUrlFields="Id" 
        NavigateUrlFormat="/_layouts/Asset/ViewDetail.aspx?id={0}" TokenNameAndValueFields="ID=Id"/>                          
    <asp:BoundField DataField="Id" Visible="false" />
    <asp:BoundField HeaderText="Localização" DataField="LocationPlace">

The code above works, but it opens the page on the browser (like if the location is changed). But what I'd like was to call javascript inside NavigateUrlFormat:

<SharePoint:SPMenuField HeaderText="Title" TextFields="Name" MenuTemplateId="ActionsMenu" NavigateUrlFields="Id" 
            NavigateUrlFormat="javascript:showDialog('/_layouts/Asset/ViewDetail.aspx?id={0}'" TokenNameAndValueFields="ID=Id"/>  

I've found a possible workaround here, but this is not working because SPUrlUtility.AllowedProtocols is returning a clone of the list (and changing on value of a clone won't change the root value itself)

Has anyone had this problem?

Any help would be appreciated.

Thank you

share|improve this question
I'm looking for the same thing a javascript based Modal to popup the navigate url. Doesn't seem to have a straight forward approach in SP after all this years – Shaamil Sep 18 '14 at 13:13

One option would be to create a control redirect using the .browser file. This way you can replace any SPGridView with your own class. THe problem there is of course that this will be an app wide change... The redirect would allow you to use your own custom (derived from SPGridview) control, in which you could change the default behavior of the control.

share|improve this answer

NunoC, try this jquery function:

.bind('click', null, function () { alert(this.href); return false; });
share|improve this answer

It took me a little bit more jQuery than that, but it worked for me: I'm running into some issues using the $ for jQuery, and find myself forced to use the full jQuery format instead.

This is replacing the href and the click event handler and opening the original href in a modal dialog

function openDialog(url)
   var dialogOptions = SP.UI.$create_DialogOptions();
   dialogOptions.url = url;

jQuery(document).ready( function()
    jQuery('.ms-vb >').each( function(index) {
        var thisEntry = jQuery(this);
        var href = thisEntry.attr('href');
        thisEntry.attr('href', 'javascript:;'); () 
share|improve this answer

I've also used Jorge's solution in a 2010 project successfully. When upgrading to 2013 however, simply replace with

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.