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

DestroyOnClose not working with client-side close

3 Answers 284 Views
Window
This is a migrated thread and some comments may be shown as answers.
Craig Wallace
Top achievements
Rank 1
Craig Wallace asked on 10 Aug 2010, 03:13 PM
Hi,

I am using client script to close my RadWindow after postback, as follows:

<telerik:RadWindowManager ID="rwmWindow" Width="500px" Height="375px" 
    runat="server" DestroyOnClose="true" Modal="true" VisibleOnPageLoad="false" 
    Title="New Rad Window">
    <Windows>
        <telerik:RadWindow ID="rwWindow" runat="server" ReloadOnShow="true" ShowContentDuringLoad="false" DestroyOnClose="true" Behaviors="Close,Resize,Move" OpenerElementID='<%# Parent.FindControl("btnMyLaunchButton").ClientID %>'>
            <ContentTemplate>
            <script language ="javascript" type ="text/javascript" >
                function GetRadWindow() {
                    var oWindow = null;
                    if (window.radWindow)
                        oWindow = window.RadWindow; //Will work in Moz in all cases, including clasic dialog       
                    else if (window.frameElement.radWindow)
                        oWindow = window.frameElement.radWindow; //IE (and Moz as well)       
                    return oWindow;
                }
  
                function Close() {
                    GetRadWindow().Close();
                }           
                </script
<div class="window">
<p>This is the new rad window</p>
                <asp:literal ID="litClose" runat="server" Visible="false"></asp:literal>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Submit_Click"/>
                </div>
            </ContentTemplate>
    </telerik:RadWindow>        
    </Windows>
</telerik:RadWindowManager>

Now within Submit_Click I update the literal as follows:

litClose.Text =

 

"<script type='text/javascript'>Close()</" + "script>";

 

 


This works fine, but the DestroyOnClose attribute of the window seems to be ignored as when I next launch the window, the contents are still there.

How can I destroy the window using the client-side close?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 13 Aug 2010, 10:41 AM
Hello Craig Wallace,

Please, note that  it is not valid to use the DestroyOnClose property with value true when the content is on the same page because this will destroy the inner controls and you should recreate them. To clear the content in the controls with ViewState inside the RadWindow, you can directly assign empty or default value either in the OnClientClose event on the client or on the server, depending on your logic. Referencing the controls can be done directly because they reside on teh same page which is much easier than referencing them when they are in an external page loaded in the RadWindow.

Sincerely yours,
Svetlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Craig Wallace
Top achievements
Rank 1
answered on 13 Aug 2010, 11:41 AM
Hi Svetlina,

Can you give me an example of how I can call server-side code with OnClientClose?  Or an example of client-side code?

I have tried this:

function ClientClose(sender, eventArgs) {
   $find("<%= txtNumber.ClientID %>").Value = "";
   $find("<%= txtCustomerName.ClientID %>").Value = "";
   var calendar = $find("<%= txtCallbackDate.ClientID %>");
   var dates = calendar.get_selectedDates();
   calendar.unselectDates(dates);
   $find("<%= dlCallbackType.ClientID %>").Value = "";
   $find("<%= txtCallbackNotes.ClientID %>").Value = "";
}

but nothing happens, and I don't get reliable exception handling either.

Craig
0
Georgi Tunev
Telerik team
answered on 18 Aug 2010, 12:59 PM
Hi Craig Wallace,

To call a server-side function from JavaScript, you can manually call __doPostBack() or RadAjax's ajaxRequest.
A sample showing the last approach is available in the Edit Dialog for RadGrid demo where the refreshGrid() function makes an ajax call to rebind the grid on the server.


All the best,
Georgi Tunev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Window
Asked by
Craig Wallace
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Craig Wallace
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or