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

Refresh Update Panel on Window Close

1 Answer 409 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jeff Paetkau
Top achievements
Rank 1
Jeff Paetkau asked on 17 Nov 2009, 07:43 PM
Hi,

We have an in-house CMS. Various functionality happens in modules. Any number and configuration (including duplicates) of modules can be added to a page. Users with appropriate permissions can open a RadWindow that contains a page where they can update the settings for that module.

Currently, when they close the window the whole page reloads with their updated settings. This works but we would like to make it better.

However, we would like to modify this behavior. Each module is wrapped in an update panel. When the RadWindow closes only the appropriate update panel is updated. Even then, if possible it should only update if they click the "update" button in the window and not if they click the "cancel" button or the "X" on the RadWindow.

I have found one solution. However, it seems "hackish".
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Random_String_Control.ascx.cs" Inherits="AJAX_Test.Random_String_Control" %> 
 
<asp:UpdatePanel UpdateMode="Conditional" runat="server"
    <ContentTemplate> 
        <script type="text/javascript"
            function clientClose_<%= Refresh_Random_String.ClientID %>(sender, args) { 
                document.getElementById('<%= Refresh_Random_String.ClientID %>').click(); 
            } 
        </script> 
        <asp:Literal runat="server" ID="Random_String" /> 
        <asp:Button ID="Refresh_Random_String" runat="server" OnClick="Refresh_Random_String_Click" Text="Refresh Random String" /> 
        <rad:RadWindow ID="Window" runat="server" Modal="true" NavigateUrl="http://google.ca" /> 
        <asp:Button ID="Open_Window" runat="server" Text="Open Window" OnClick="Open_Window_Click" /> 
    </ContentTemplate> 
</asp:UpdatePanel> 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
namespace AJAX_Test 
    public partial class Random_String_Control : System.Web.UI.UserControl 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if(!IsPostBack) 
                Random_String.Text = Guid.NewGuid().ToString(); 
            Window.VisibleOnPageLoad = false
            Window.OnClientClose = "clientClose_" + Refresh_Random_String.ClientID; 
        } 
 
        protected void Open_Window_Click(object sender, EventArgs e) 
        { 
            Window.VisibleOnPageLoad = true
        } 
 
        protected void Refresh_Random_String_Click(object sender, EventArgs e) 
        { 
            Random_String.Text = Guid.NewGuid().ToString(); 
        } 
    } 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="AJAX_Test._Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager runat="server" /> 
        <div> 
            1 : 
            <asp:PlaceHolder ID="One" runat="server" /> 
        </div> 
        <br /> 
        <div> 
            2 : 
            <asp:PlaceHolder ID="Two" runat="server" /> 
        </div> 
        <br /> 
        <div> 
            3 : 
            <asp:PlaceHolder ID="Three" runat="server" /> 
        </div> 
    </form> 
</body> 
</html> 
 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
namespace AJAX_Test 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            One.Controls.Add(Page.LoadControl("Random_String_Control.ascx")); 
            Two.Controls.Add(Page.LoadControl("Random_String_Control.ascx")); 
            Three.Controls.Add(Page.LoadControl("Random_String_Control.ascx")); 
        } 
    } 
 




Is there an easier way to do this?

Thanks,
Jeff Paetkau

PS: If you attempt to attach a zip file, you get the error "File is not of correct type." However, there does not appear to be any way to remove the file. It seems the only way to continue posting is to attach an image.

1 Answer, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 18 Nov 2009, 02:06 PM
Hello Jeff,

If I understand your setup correctly, this problem is not directly related to the RadWindow control - you open the dialog, close it and the RadWindow's OnClientClose client-side event is fired. From this point on, you need to find a way to trigger a panel refresh by using JavaScript. If this is the case, I suggest to check the Net for possible solutions - for example this article could be of help:
http://codeclimber.net.nz/archive/2007/06/26/How-to-refresh-an-UpdatePanel-from-javascript.aspx

As for executing the JavaScript code only when the Update button in the content page is clicked, you can implement a simple if/else logic in the OnClientClose event handler. For example you can pass an argument from the content page as shown in this help article and to check for that argument in the OnClientClose event handler.


All the best,
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
Jeff Paetkau
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Share this question
or