This is a migrated thread and some comments may be shown as answers.

RadAlert not in radwindowmanager window array

1 Answer 108 Views
Window
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 15 Jan 2014, 12:08 PM
Hello,

I have a radwindowmanager in a master page, with 2 radwindows defined, and an alert template, like so:

<telerik:RadWindowManager ID="myId" runat="server" ReloadOnShow="true"<br>
        OnClientShow="Hideloading" DestroyOnClose="true"><br>
        <AlertTemplate><br>
            <div class="rwDialogPopup radalert"><br>
                <div class="rwDialogText"><br>
                    <div class="space"><br>
                    </div><br>
                    <b>{1}</b><br>
                    <br /><br>
                    <a onclick="$find('{0}').close();FocusLastFocusedControl();" onkeypress="return GetChar(event,'{0}');"<br>
                        class="rwPopupButton" href="javascript:void(0);"><span class="rwOuterSpan"><span<br>
                            class="rwInnerSpan">##LOC[OK]##</span> </span></a><br>
                    <div class="clear"><br>
                    </div><br>
                </div><br>
            </div><br>
        </AlertTemplate><br>
        <Windows><br>
            <telerik:RadWindow ID="id1" AutoSize="true" Modal="true" Title="title1"<br>
                runat="server"  KeepInScreenBounds="true" VisibleStatusbar="false"<br>
                RegisterWithScriptManager="true" Behaviors="Close, Move, Resize" Height="450px"<br>
                OnClientBeforeShow="ClientShow" AutoSizeBehaviors="Height"><br>
                <ContentTemplate><br>
                    <%--  ... --%><br>
                </ContentTemplate><br>
            </telerik:RadWindow><br>
            <telerik:RadWindow ID="id2" AutoSize="true" Modal="true" ReloadOnShow="True"<br>
                 KeepInScreenBounds="true" VisibleStatusbar="false"<br>
                RegisterWithScriptManager="true" Behaviors="Move, Resize"<br>
                DestroyOnClose="true" runat="server" OnClientClose="CloseAddNoteWindow" Title="title2"><br>
                <ContentTemplate><br>
                    ...<br>
                </ContentTemplate><br>
            </telerik:RadWindow><br>
        </Windows><br>
    </telerik:RadWindowManager>



Now, from a client page I try to catch any error and show a message to the user via radalert by calling it from code-behind, like so:

RadWindowManager1.RadAlert(ex.Message, 450, 210,
                                                      ex.Message,
                                                      string.Empty);



What I'm trying to do is check if multiple radalerts are open, close them and show only one radalert with a generic message. I try to do this in the master page like this

Sys.Application.add_load(loadHandle);
 
            function loadHandle() {
                var wManager = GetRadWindowManager();
                var windows = wManager.get_windows();
                var wCount = windows.length;
                if (wCount > 3)
                {
                    //close all pop-ups and display a generic message pop-up about multiple errors
                    wManager.closeAll();
                    radalert('Multiple errors', null, null, 'Multiple errors');
                }
            }


The problem is that 'wManager.get_windows();' only contains the 2 RadWindows I have defined, and not the radalerts. Why is that? Is there some other way I can achieve what I want?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 16 Jan 2014, 12:50 PM
Hi Nick,

RadAlerts, RadConfirms and RadPrompts are templated popups that are not added in the windows collection of the manager because they are disposed as soon as they are closed.

Perhaps handling multiple errors can be done by concatenating messages on the server, or counting error occurrences on the server to determine the final message to be shown.

Another approach would be a JavaScript counter that can be increased with each alert call so you could check this counter for many alerts, e.g.:
markup
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<asp:Button ID="Button1" Text="postback" runat="server" />
code-behind mockup
protected void Page_Load(object sender, EventArgs e)
{
    RadWindowManager1.RadAlert("one", null, null, "", "");
    IncreaseAlertCount();
    RadWindowManager1.RadAlert("two", null, null, "", "");
    IncreaseAlertCount();
    RadWindowManager1.RadAlert("three", null, null, "", "");
    IncreaseAlertCount();
}
 
 
protected void IncreaseAlertCount()
{
    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),Guid.NewGuid().ToString(), "alertCounter++;", true);
}

script on the page:
Sys.Application.add_load(loadHandle);
 
var alertCounter = 0;
 
function loadHandle()
{
    var wManager = GetRadWindowManager();
    setTimeout(function ()
    {
        //check predefined dialogs count
        if (alertCounter > 2)
        {
            //close the mall and show common alert
            closePredefinedDialogs();
            wManager.radalert("too many errors");
            //reset counter
            alertCounter = 0;
        }
    }, 0);
}
 
function closePredefinedDialogs()
{
    //get all popup elements
    $telerik.$(".RadWindow").each(function (index, elem)
    {
        //build the Component name from the popup element ID
        var ctrl = $find(elem.getAttribute("id").substring(17));
        //check if it is a predefined dialog (RadAlert, RadConfirm, RadPrompt) and close it as if the [x] button is clicked
        if (ctrl && ctrl._isPredefined && ctrl.isVisible())
            ctrl.close(null);
    });
}


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Window
Asked by
Nick
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or