Вопрос

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>

Page:

<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>

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:

Page:

<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 Behind eventually calls this after database work completes:

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

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'?

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;
    }

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

Другие советы

I'm pretty sure that I've run into this issue before, and I think this fixed it:

setTimeout("self.close()", 1000);

If that doesn't work, try this:

setTimeout("self.focus()", 500); //adjust the timeout as needed
setTimeout("self.close()", 1000);

You can also do it this way if you'd prefer:

setTimeout(function(){
    self.close();
}, 1000);

I'm not sure if I am improving this answer, I'm just trying to make it easier to understand. I have a rad window that is opened from a main page. The radwindow is opened in Code Behind (C#), not Javascript. When my user clicks a Save button on the RadWindow, it performs some logic tasks, then it closes the radwindow itself. You simply need to:

Put thise code block in you RadWindow aspx.....

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

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

</script>
</telerik:RadCodeBlock>

Put this code in your RadWindow's button click after you perform your pre-close logic (the same button that performs the other logic closes the window)

C# ClientScript.RegisterStartupScript(typeof(string), "", "CloseDialog();");

OR

VB ClientScript.RegisterStartupScript(Me.GetType(), "", "CloseDialog();")

If you're wondering how to open the radwindow from codebehind here is how I did it:

RadWindow window1 = new RadWindow();
// Set the window properties   
window1.NavigateUrl = "winStrengthChart.aspx?EMPLOYIDNAME=" + parmString;
window1.ID = "RadWindow1";
window1.Width = 800;
window1.Height = 650;
window1.VisibleStatusbar = false;
window1.Behaviors = Telerik.Web.UI.WindowBehaviors.Close | Telerik.Web.UI.WindowBehaviors.Resize | Telerik.Web.UI.WindowBehaviors.Move;
window1.VisibleOnPageLoad = true; // Set this property to True for showing window from code   
rwm1.Windows.Add(window1);
this.Form1.Controls.Add(window1);   

...AND of course you need a basic RadWindowManager on the main page that opens the window:

<telerik:RadWindowManager ID="rwm1" runat="server">
<Windows>
</Windows>
</telerik:RadWindowManager>

This should work if I have made a mistake please correct me.

Thanks

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top