从服务器调用JavaScript的关闭RadWindow [英] Closing RadWindow by invoking javascript from server

查看:437
本文介绍了从服务器调用JavaScript的关闭RadWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制,看起来像这样:

I have a Control that looks like this:

<telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
        function refresh() {
            window.$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindRecommendations");
        }
    </script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="AjaxRequest">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="NameOfGrid" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
        <telerik:RadWindow ID="RadWindow1" runat="server" NavigateUrl="UrlOfPage" OnClientClose="refresh"></telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>

页:

<script type="text/javascript">
    function closeWindow() {
        self.close();
        return false;
    }
</script>
<!-- form fields here -->
<telerik:RadButton runat="server" ID="_cancel" Text="Cancel" OnClientClick="closeWindow"></telerik:RadButton>
<telerik:RadButton runat="server" ID="_submit" Text="Submit" OnClientClick="closeWindow" OnClick="DoSomeDataBaseStuff"></telerik:RadButton>

这按预期工作。我RadWindow被删除,我的控制的网格刷新后击中无论是取消或提交按钮。问题是,该数据库还没有完成做那个时候的工作,使电网刷新不露的变化。我试图切换我实现的页面看起来是这样的:

This works as intended. My RadWindow is removed and my control's grid refreshes upon hitting either the cancel or submit buttons. The problem is that the database isn't finished doing its work by that time so the grid refresh doesn't reveal the changes. I have attempted to switch my implementation of page to look like this:

页:

<script type="text/javascript">
    function closeWindow() {
        self.close();
        return false;
    }
</script>
<!-- form fields here -->
<telerik:RadButton runat="server" ID="_cancel" Text="Cancel" OnClick="CallJavaScriptToKillWindow"></telerik:RadButton>
<telerik:RadButton runat="server" ID="_submit" Text="Submit" OnClick="DoSomeDataBaseStuffAndThenCallJavaScriptToKillWindow"></telerik:RadButton>

code背后,最终会调用这个数据库的工作完成后:

Code Behind eventually calls this after database work completes:

ClientScript.RegisterStartupScript(GetType(), "Key", "closeWindow();", true);

我打我的断点在closeWindow功能,但它不具有相同的行为(窗口并不真正关闭)。我已经试过各种重复这样的:

I hit my breakpoint in the closeWindow function, but it doesn't have the same behavior (the window doesn't actually close). I've tried various iterations like:

ClientScript.RegisterStartupScript(GetType(), "Key", "$(document).ready(function() {return closeWindow();});", true);

无济于事。我在想什么?

to no avail. What am I missing?

推荐答案

什么是自我?难道你的意思是本?

What is 'self'? Don't you mean 'this'?

您想从窗口内或从启动窗口的页面关闭RadWindow?

Are you trying to close the RadWindow from inside the window or from the page that launches the window?

这里面的一个窗口,我通常这样做:

From inside a window, I usually do this:

    function GetRadWindow()
    {
        var oWindow = null;
        if (window.radWindow)
            oWindow = window.radWindow;
        else if (window.frameElement.radWindow)
            oWindow = window.frameElement.radWindow;
        return oWindow;
    }

    function Close()
    {
        var oWindow = GetRadWindow();
        oWindow.argument = null;
        oWindow.close();
        return false;
    }

另外,我会使用ScriptManager.RegisterStartupScript而不是ClientScript。

Also, I'd use ScriptManager.RegisterStartupScript rather than ClientScript.

这篇关于从服务器调用JavaScript的关闭RadWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆