Showing posts with label Dialog. Show all posts
Showing posts with label Dialog. Show all posts

Thursday, October 16, 2014

How to close a layouts page loaded in an SPModalDialog from server side

ASP:
// In _layouts\YourSolution\dialogpage.aspx:

<asp:Button ID="btnSaveAndClose" runat="server" OnClick="btnSaveAndClose_Click" />

C#:


protected void btnSaveAndClose_Click(object sender, EventArgs e)
{
    // code logic before closing the dialog
    // ..
    // ..
    
    string script = @"window.frameElement.commonModalDialogClose(1, '');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close", script, true);
    
    // alternatives for the script variable are:
    // string script = @"window.frameElement.commitPopup();";
    // string script = @"window.frameElement.cancelPopUp();";

    // NOTE: use RegisterStartupScript when executed from .ASCX/webpart:  
    // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Close", script, true);
}

A small gotcha I ran into is that I had the btnSaveAndClose control Ajaxified, which caused it to throw exceptions such as:

"0x800a1391 - JavaScript runtime error: 'Sys' is undefined"

and

"0x800a1391 - JavaScript runtime error: 'ULSSendExceptionImpl' is undefined"

Thursday, February 14, 2013

How to refresh parent page after closing a SP.UI.ModalDialog

var options = {
 
url:'/_layouts/YourAspx/YourPage.aspx',
 title: 'Your Application Page Title',
 allowMaximize: false,
 showClose: true,
 width: 700,
 height: 260,
 dialogReturnValueCallback: RefreshOnDialogClose
 };
SP.UI.ModalDialog.showModalDialog(options);


Key here is the callback function; set it to RefreshOnDialogClose. Dead simple ;-)

Friday, May 11, 2012

How to block the execution thread using RadConfirm

Finally found a way to use the RadConfirm popup, which is invoked from client side, in combination with server side events. Following example will display the confirmation window and only continues to call the button click event IF the OK button is clicked by the user.


ASPX:


<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
</telerik:RadWindowManager>

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">

        var lastClickedItem = null;
        var clickCalledAfterRadprompt = false;
        var clickCalledAfterRadconfirm = false;

        function onClientButtonClicking(sender, args) {
            if (args.get_item().get_text() == "Order another beer") {
                if (!clickCalledAfterRadconfirm) {
                    args.set_cancel(true);
                    lastClickedItem = args.get_item();
                    radconfirm("Are you sure? You order it, you finish it!", confirmCallbackFunction);
                }
            }
        }

        function confirmCallbackFunction(args) {
            if (args) {
                clickCalledAfterRadconfirm = true;
                lastClickedItem.click();
            }
            else
            clickCalledAfterRadconfirm = false;
            lastClickedItem = null;
        }  

    </script>
</telerik:RadCodeBlock>

<CommandItemTemplate>
    <telerik:RadToolBar ID="RadToolBar1" runat="server" OnClientButtonClicking="onClientButtonClicking" OnButtonClick="RadToolBar1_ButtonClick" Width="100%">
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
            <Items> 
                <telerik:RadToolBarButton CommandName="OrderBeer" runat="server" Text="Order another beer"></telerik:RadToolBarButton> 
            </Items> 
    </telerik:RadToolBar>
</CommandItemTemplate>

The CommandItemTemplate part you obviously need to add to your MasterTableView element..



CS:



protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
    {
        RadToolBarButton button = e.Item as RadToolBarButton;
        if (button.CommandName == "OrderBeer")
        {
            \\Do stuff, drink the beer
            \\DrinkBeer();
        }
    }

Have a nice weekend folks!!!


Thursday, April 21, 2011

VB function to invoke dialog box for file selectoin

Small piece of code but really handy for file selections. Important, make sure that the Microsoft Office xx.x Object Library is checked, otherwise the Dialog object will not be recognized:
Function FindTxtFile(strFNme As String, strSearchPath As String, strTitle As String) As String
 Dim myDialog As FileDialog
 Dim vrtSelectedItem As Variant
Set myDialog = Application.FileDialog(msoFileDialogOpen)
With myDialog
    .AllowMultiSelect = False
    .Filters.Add "Text", "*.txt", 1
    .Title = strTitle
'    Debug.Print Right(strSearchPath, Len(strSearchPath) - 10)
    .InitialFileName = strSearchPath & strFNme
    If .Show = -1 Then
        For Each vrtSelectedItem In .SelectedItems
            FindTxtFile = Trim(vrtSelectedItem)
        Next vrtSelectedItem
    Else
    End If
   Set myDialog = Nothing
End With
End Function