Question

I have the following scenario: A user makes a click on a button inside an asp page. Because of security reasons, during the click event execution the system determines that it is necessary to apply some validations before continuing with the execution of the fired event.

Those validations are shown in a window (in this case a Telerik RadWindow). Inside this RadWindow, there is a web user control (WUC) containg validations like a Captcha, or security code, secret questions, etc. After the user writes the captcha text or the necessary validations (it implies postbacks inside the WUC), the WUC should continue with the execution of the fired event from the botton which opened the RadWindow.

How can I do this? Any idea? Is it possible?

Was it helpful?

Solution

When you call your RadWindow, make sure the set the OnClientClose event. If you are creating your RadWindow from code-behind:

RadWindow newWindow = new RadWindow();
newWindow.OnClientClose = "onRadWindowClosed";
...

If you are opening your RadWindow through javascript, you can use the add_close() method:

...
getRadWindow().add_close('onRadWindowClosed');
...

In either case, you need to create a new event handler script on your calling page for the OnClientClose event:

function onRadWindowClosed(sender, eventArgs) {
    var returnValue = eventArgs.get_argument();

    if (returnValue != null) {
        if (returnValue == "continue") {
            // Continue doing work
        }
        else {
            // Throw an error
        }
    }
}

On your WUC, in the btnContinue click event:

protected void btnContinue_Click(object sender, EventArgs e)
{         
    Page.ClientScript.RegisterClientScriptBlock(GetType(), "closeScript", "getRadWindow().close('continue');", true);
}

This function is used on both pages:

function getRadWindow() {
    var oWindow = null;

    if (window.radWindow) 
        oWindow = window.radWindow;
    else if (window.frameElement.radWindow) 
        oWindow = window.frameElement.radWindow;

    return oWindow;
}

UPDATE TO THE EXISTING ANSWER

On your calling page, add a function to get the RadAjaxManager (assuming you already have on the page. If not, you'll need one):

function get_ajaxManager() {
    return $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>");
}

Modify your OnClosed javascript function (from the calling page):

function onRadWindowClosed(sender, eventArgs) {
    var returnValue = eventArgs.get_argument();

    if (returnValue != null) {
        if (returnValue == "continue") {
            // This call will invoke a server side event
            get_ajaxManager().ajaxRequest("continue~");
        }
    }
}

In your code-behind, handle the server-side event that gets called:

protected void RadAjaxManager1_Request(object source, Telerik.Web.UI.AjaxRequestEventArgs e)
{
    try
    {
        if (e.Argument.Trim().Length == 0)
        {
            // Show a message when debugging, otherwise return
            return;
        }

        string argument = (e.Argument);
        String[] stringArray = argument.Split('~');

        switch (stringArray[0])
        {
            case "continue":
                // Continue performing your action or call a specific method
                ServerSideMethodCall();
                break;
        }
    }
    catch (Exception ex)
    {
        RadAjaxManager.GetCurrent(this.Page).Alert("Unable to complete operation at this time: " + ex.Message);
    }
}

As previously mentioned, you'll need a RadAjaxManager on the page if you don't already have one, and you'll need to tie the AjaxRequest handler to it.

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_Request"></telerik:RadAjaxManager>

Sorry for the long-winded answer. Let me know if that gets you what you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top