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

Close RadWindow From Codebehind and refresh parent page

8 Answers 1879 Views
Window
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 17 Apr 2008, 02:51 AM
Good evening.  There are hundreds of posts on closing the window client side but what i am using the radwindow for is cropping an image and then executing the cropping on codebehind and updating the database.  Once the database is updated, i need to close the radwindow and then reload the parent page.  I know how to close it client size but not from codebehind after completing a the database update. 

If it is possible, is there anyway to give and example of closing the window and refreshing the parent page that popped with window as well as an example the just closes the window. 

I want to thank you for your help sincerly in advance.

joshua

8 Answers, 1 is accepted

Sort by
0
Shaun Peet
Top achievements
Rank 2
answered on 17 Apr 2008, 01:23 PM
Hello Joshua,

To the best of my knowledge, the window can only be closed using client-side script.  That said, however, you can generate the code needed to trigger the closing of the window on the server-side.  If you're not using ajax, you can use Page.ClientScript.RegisterStartupScript().  If you're using a RadAjaxManager, then you can use RadAjaxManager1.ResponsScripts.Add().  The latter option would provide a seamless user experience while the former would cause a slight screen flicker prior to closing the window.

Have a close look at the following code library project as it does exactly what you're trying to do.  There is a server-side Close function that generates the client-side script needed to close the window and refresh the parent:

http://www.telerik.com/community/code-library/submission/b311D-bbcdde.aspx

0
Chris
Top achievements
Rank 1
answered on 10 Apr 2009, 10:33 PM
Thanks Shaun,

That worked for me.  Seems extremely painful to do a close and refresh but I guess that's why we have Silverlight.  :)

0
Shaun Peet
Top achievements
Rank 2
answered on 11 Apr 2009, 04:06 AM
Hello Chris, glad to help out.

Since this original post Telerik (and MS) have made it a ton easier to implement web-service based data fetching for their controls, so the parent page 'refreshing' can be done virtually all client-side which is essentially the same as Silverlight.  That's about the only improvement I've made to my methodology - that, and I've re-designed the pop-up windows.
0
John Davis
Top achievements
Rank 2
answered on 18 Nov 2009, 04:30 PM

I need to refresh (postback) the parent window after a radwindow closes, if possible using code behind to set it up.

It looks like I could use this example, but I am not skilled in javascript.  Can you help adapt to this specific situation?  I am opening a radwindow in code behind in ItemCommand.
From the example I guess I need to put the following into the aspx:
    function CloseAndRebind(HFID) { get_RadWindow().BrowserWindow.postBackHF(HFID); get_RadWindow().Close(); }

But what code do I put in ItemCommand event handler?

Below is the code I have now.

John

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
     
            ...

            'http://www.telerik.com/community/forums/aspnet-ajax/window/how-to-use-radwind-from-server-side-code.aspx
            Dim script As String = [String].Format("openWindow(""{0}"");", sUrl)
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "openWin", script, True)
            'following from: http://www.telerik.com/community/code-library/aspnet-ajax/general/administration-site-template-starter.aspx
            'CType(Master.FindControl("ramModal"), Telerik.Web.UI.RadAjaxManager).ResponseScripts.Add("CloseAndRebind('" & Request.QueryString("HFID") & "')")
        End If
    End Sub

----------------------------------------------------------

<%@ Page Title="" Language="VB" MasterPageFile="~/WithMenu.master" AutoEventWireup="false" CodeFile="EditUsers.aspx.vb" Inherits="General_EditUsers" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="rad" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<%--<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> --%>
<script type="text/javascript">  
     function openWindow(url)  
     {   
        setTimeout('var win = radopen("'+url+'",null)',50);
    }
    function CloseAndRebind(HFID) { get_RadWindow().BrowserWindow.postBackHF(HFID); get_RadWindow().Close(); }
</script>
<table style="width:100%;">
<tr>
<td>
<asp:label id="lblError" runat="server" Width="986px" Font-Bold="True" ForeColor="Red"></asp:label>
</td>
</tr>
<tr>
<td>
<rad:RadGrid ID="RadGrid1" skin="Vista" GridLines="None" runat="server"
 PageSize="10" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="OD1" OnInsertCommand="RadGrid1_InsertCommand"
ondeletecommand="RadGrid1_DeleteCommand"
onitemcreated="RadGrid1_ItemCreated" onitemupdated="RadGrid1_ItemUpdated"
OnEditCommand="RadGrid1_EditCommand" OnCancelCommand="RadGrid1_CancelCommand"
OnInit="RadGrid1_Init" AllowFilteringByColumn="true"
>
<PagerStyle Mode="NextPrevAndNumeric" />
<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="PersonID"
DataSourceID="OD1" HorizontalAlign="NotSet" AutoGenerateColumns="False">
<Columns>
<rad:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
<ItemStyle CssClass="MyImageButton" />
</rad:GridEditCommandColumn>
<rad:GridBoundColumn DataField="PersonID" HeaderText="SC_SKU_ID"
UniqueName="PersonID" Readonly="true" Visible="false">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="LastName" HeaderText="Last Name" SortExpression="LastName"
UniqueName="LastName" ColumnEditorID="GridNumericColumnEditor1">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="FirstName" HeaderText="First Name" SortExpression="FirstName"
UniqueName="FirstName">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="PermissionID" HeaderText="PermissionID" SortExpression="PermissionID"
UniqueName="PermissionID" Readonly="true" >
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="PermissionName" HeaderText="Permission" SortExpression="PermissionName"
UniqueName="PermissionName">
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Userid" HeaderText="Userid" SortExpression="Userid"
UniqueName="Userid">
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Password1" HeaderText="Password" SortExpression="Password1"
UniqueName="Password1">
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="SNet_ID" HeaderText="SNet_ID" SortExpression="SNet_ID"
UniqueName="SNet_ID" Readonly="true" >
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="SNet_Name" HeaderText="SNet" SortExpression="SNet_Name"
UniqueName="SNet_Name" Readonly="true" >
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="SCS_Name" HeaderText="SCS" SortExpression="SCS_Name"
UniqueName="SCS_Name">
 <HeaderStyle Width="70px" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Address1" HeaderText="Address1" UniqueName="Address1" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="Address2" HeaderText="Address2" UniqueName="Address2" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="City" HeaderText="City" UniqueName="City" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="State" HeaderText="State" UniqueName="State" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="Zip1" HeaderText="Zip1" UniqueName="Zip1" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="Zip2" HeaderText="Zip2" UniqueName="Zip2" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="CellPhone" HeaderText="Cell" UniqueName="CellPhone" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="Email" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="Fax" HeaderText="Fax" UniqueName="Fax" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="LandPhone" HeaderText="Phone" UniqueName="LandPhone" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="PhoneExtension" HeaderText="PhoneEx" UniqueName="PhoneEx" Visible="false">
    </rad:GridBoundColumn>
    <rad:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title" Visible="false">
    </rad:GridBoundColumn>
<rad:GridButtonColumn ConfirmText="Delete this person?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
UniqueName="DeleteColumn">
<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
</rad:GridButtonColumn>
<rad:GridButtonColumn Text="Link to SCS" CommandName="Select" UniqueName="Select" >
</rad:GridButtonColumn>
</Columns>
<EditFormSettings CaptionFormatString="" UserControlName="EditUsersControl.ascx" EditFormType="WebUserControl">

<FormTableItemStyle Wrap="False"></FormTableItemStyle>
<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
Width="100%" />
<FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<EditColumn ButtonType="ImageButton" InsertText="Insert" UpdateText="Update record"
UniqueName="EditCommandColumn1" CancelText="Cancel edit">
</EditColumn>
<FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
</EditFormSettings>
</MasterTableView>
<%--<ClientSettings>
<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>--%>
</rad:RadGrid>
</td>
</tr>
<tr>
<td>
<asp:ObjectDataSource ID="OD1" runat="server" EnablePaging="false"
SelectMethod="GetPersonSelectForEditEntities" TypeName="Person_linq">
<SelectParameters>
<asp:ControlParameter ControlID="lblPermissionID" Name="iPermissionIDofCaller" PropertyName="Text" />
<asp:ControlParameter ControlID="lblSNet_ID" Name="iSNet_IDofCaller" PropertyName="Text" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
<tr>
<td>
<asp:label id="lblPermissionID" runat="server" Width="64px" Visible="False"></asp:label>
<asp:label id="lblSNet_ID" runat="server" Width="64px" Visible="False" Height="19px"></asp:label>
<asp:label id="lblSelected" runat="server" Width="64px" Height="19px"
        Visible="False"></asp:label>
<asp:label id="lblPersonID_LoggedIn" runat="server" Width="64px" Visible="False"></asp:label>
</td>
</tr>
<tr>
<td>
 <rad:RadWindowManager id="Singleton" Behaviors="close, minimize, maximize, Move" VisibleStatusbar="false" runat="server">
</rad:RadWindowManager>
</td>
</tr>
<tr>
<td>
    &nbsp;</td>
</tr>
</table>
</asp:Content>

0
Georgi Tunev
Telerik team
answered on 19 Nov 2009, 10:53 AM
Hi Joshua,

I believe that the following blog post will be of help:
http://blogs.telerik.com/blogs/09-05-05/executing_javascript_function_from_server-side_code.aspx



Greetings,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Davis
Top achievements
Rank 2
answered on 20 Nov 2009, 01:34 PM

Another  Telerik representative solved this for me.
(What I needed was this specific code, not general guidance.)

Put this in parent page:

<asp:Button ID="Button1" runat="server" />

 function CloseAndRebind(HFID) { get_RadWindow().BrowserWindow.postBackHF(HFID); get_RadWindow().Close(); }
    function ClientClose()
    {
        $get("<%= Button1.ClientID %>").click();
    }

Put this in the page that is in radwindow:

function isChildOf(parentId,element) {
while(element) {
if(element.id&&element.id.indexOf(parentId)> -1) {
    return true;
}
element=element.parentNode;
}
return false;
}

 

0
ying
Top achievements
Rank 1
answered on 31 May 2011, 06:51 AM
function CloseAndRebind(HFID) { get_RadWindow().BrowserWindow.postBackHF(HFID); get_RadWindow().Close(); }
 

HFID IS WHAT????is it put the url that the page u want to rebind???
0
Georgi Tunev
Telerik team
answered on 31 May 2011, 08:02 AM
Hello Ying,

HFID is the argument passed to the postBackHF() function that is placed in the parent page.

Regards,
Georgi Tunev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Window
Asked by
Joshua
Top achievements
Rank 1
Answers by
Shaun Peet
Top achievements
Rank 2
Chris
Top achievements
Rank 1
John Davis
Top achievements
Rank 2
Georgi Tunev
Telerik team
ying
Top achievements
Rank 1
Share this question
or