SharePointAds TextOnly

Thursday, 9 June 2011

SharePoint 2010 : how to open Modal Dialog in ECB Menu

You can open model dialog in SharePoint site using the following code:

<script type="text/javascript">
function openDialog() {
     var options = {
          url: "demopage.aspx"
         width: 600,
         height: 300,
         title: "My PopUp",

    <a  onclick="javascript:openDialog(); return false;">Click Herea>
    <asp:Button ID="btnDialog" runat="server" Text="Open Dialog"  OnClientClick="javascript:openDialog(); return false;"/>

But what if you want to open dialog from ECB menu? Create new custom action in Element.xml file and in UrlAction tag use the following javascript function.

<Elements xmlns=""
        Title="Goto My Blog">     
        <UrlAction Url="javascript: function onClose(){ }
          var o = {
            url: '',
            title: 'MyBlog',
            allowMaximize: true,
            showClose: true,
            width: 700,
            height: 500,
            dialogReturnValueCallback: onClose

In above code, I created new ECB menu for “Document library”, you can create ECB menu for any lists by changing RegistrationId , you can find all required Register Id here.
If you are not able to see modal dialog then change the <UrlAction> tag with following function.

<UrlAction Url="javascript:(function () {
        var o = {
        title: 'MyBlog',
        allowMaximize: true,
        showClose: true,
        width: 700,
        height: 500
        SP.UI.ModalDialog.showModalDialog(o); }) ();"/>

No comments:

Post a Comment