Monday, 3 September 2012

Modal dialog in SharePoint 2010

Open modal dialog in Sharepoint 2010

<script type="text/javascript">
 
    function DialogCallback(dialogResult, returnValue) {
        //SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
        window.location.href = window.location.href;
    }  
    function OpenWebPage() {
        var options = {
            url: "/Lists/test/NewForm.aspx",          
            dialogReturnValueCallback: DialogCallback
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }
    </script>


just add the function name to open the modal dialog like 
 
<a class="ms-addnew" onclick="javascript:OpenWebPage(); return false;"
 href="/Lists/test/NewForm.aspx"> Add new item </a>
 
if you want to refresh your page after the modal dialog ok button press the just on-comment the second line and comment the line next to it i'e  " window.location.href ....".

No comments:

Post a Comment