Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Run user control script on root website

$
0
0

Hello,

I am working on creating a password expiration user control for my SharePoint site.   But obviously I am having trouble.  For you see, while the user control works perfectly fine on any subsite or site page, it will not work on default.aspx for any site collection

The basic concept for the user control will check a session variable and then output a modal window through the code-behind using Page.ClientScrip.RegisterClientScript(...) to call the following script:

private string createScript(string displayPage, string title)
        {
            // The string containing the script we're building. Note that the @" denotes a multi-line string.
            String scriptString =
                @"<script language=JavaScript>
                // Used to handle what the user clicked in the dialog box
                function dialogCallback(dialogResult, returnValue)
                {
                    if( returnValue == 'Cancel' )
                    {
                        // If the user decided to cancel, show a notification
                        SP.UI.Notify.addNotification('Your password will expire soon. You will be reminded again next session.');
                    }
                }

                // Configure the dialog object
                function internalOpenDialog()
                {
                    var modalDisplay = SP.UI.$create_DialogOptions();
                    modalDisplay.title = 'Password Expiration Notification';
                    modalDisplay.url = @'http://sharenetdev.txfb-ins.com/ChangePassword';
                    modalDisplay.autoSize = true;
                    modalDisplay.showClose = true;
                    modalDisplay.allowMaximize = false;
                    modalDisplay.dialogReturnValueCallback = dialogCallback;
                    return SP.UI.ModalDialog.showModalDialog(modalDisplay);
                }

                // Constructs a SharePoint modal dialog box
                function openModalURL(URL, TITLE) {
                    // Ensure that the necessary SP resources are included
                    //return SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
                    return ExecuteOrDelayUntilScriptLoaded(internalOpenDialog, 'SP.JS');
   
                }
                // Open our modal dialog box
                openModalURL( '" + displayPage + "', '" + title + "');"+ "</script>";
            return scriptString;
        }

Debugging the user control shows that it runs perfectly fine everytime on default.aspx or any other web page. But it will never popup the modal on default.aspx.

Does anyone know what is going on?


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>