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

access window event from inside the page in the radwindow?

3 Answers 96 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jacob Button
Top achievements
Rank 1
Jacob Button asked on 14 Oct 2009, 07:15 PM
I have a RadWindow with a page inside of it. There is a javascript function on this page which (using RadAjaxManager) asynchronously updates another control every 10 seconds.  It does this through calling setTimeout on itself every time it fires.  This is working the way I want it to.  The problem is that once I close the window the javascript function is still firing every 10 seconds calling the the ajax postback.

I want to be able to cancel the timeout when the window is closed but I have no idea how to detect that event from the page inside the window.  Any help?

All of this code is in the page that is contained in the radwindow

Javascript:
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
        <script language="javascript" type="text/javascript"
            function UpdateComments() { 
                var ajaxManager = $find("<%= WorkbinItemAjaxManager.ClientID%>");   
                ajaxManager.ajaxRequestWithTarget('<%= RefreshListBttn.UniqueID%>', ''); 
                updatingComments = setTimeout ( "UpdateComments()", 10000 );   
            } 
 
            var updatingComments = setTimeout ( "UpdateComments()", 10000 ); 
 
        </script> 
    </telerik:RadScriptBlock> 

AjaxManager
    <telerik:RadAjaxManager ID="WorkbinItemAjaxManager" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RefreshListBttn"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="CommentsListBox" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="InsertCommentBttn" > 
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="NewComment" /> 
                    <telerik:AjaxUpdatedControl ControlID="CommentsListBox" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

Controls
<asp:TextBox ID="NewComment" runat="server" TextMode="MultiLine" EmptyMessage="Add Comment Here..." 
        Rows="3" Width="95%" style="margin-top:5px;"  /> 
 
<asp:Button ID="InsertCommentBttn" runat="server" Text="Add Comment" OnClick="InsertComment" /> 
<asp:Button ID="RefreshListBttn" runat="server" Text="Refresh List" OnClick="RefreshList" /> 
 
 
<telerik:RadListBox ID="RadListBox1" runat="server" Height="100%" Width="100%"  
    DataSourceID="CommentsDataSource" DataKeyField="Comment_ID" OnItemDataBound="Comments_ItemDataBound" > 
</telerik:RadListBox> 


Every 10 seconds the javascript fires the RefreshButton onclick event which refreshes the ListBox.  When the window is closed I want to run some javascript like      clearTimeout(updatingComments);   which will stop the javascript from firing when the window is closed.


On an unrelated note, but still something that's bothering me,  When I added the ListBox into the UpdatedControls on the AjaxManager the height=100% attribute of the list box stops working.  Whats the best way around this?  Thanks for any help.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 16 Oct 2009, 10:40 AM
Hi Jacob,

By default, RadWindow instances are cached to speed up response time after the first time they are shown and is not destroyed, thats why the event fires even after window closes. You can prevent this caching by setting the DestroyOnClose property to True.

Try setting the  DestroyOnClose property of RadWindow to True and see whether it helps.

-Shinu.
0
Jacob Button
Top achievements
Rank 1
answered on 16 Oct 2009, 03:48 PM
:)

Thank you shinu, that did the trick.

Now any idea why my 100% height isn't working anymore?  I know I can set the height via javascript everytime the page is resized.... but that's just obnoxious.
0
Georgi Tunev
Telerik team
answered on 21 Oct 2009, 07:56 AM
Hi Jacob,

Try setting UpdatePanelsRenderMode to Inline and see if this fixes the problem.


Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Window
Asked by
Jacob Button
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jacob Button
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or