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

Open RadWindow Server-Side fires only once

3 Answers 417 Views
Window
This is a migrated thread and some comments may be shown as answers.
Glen
Top achievements
Rank 1
Glen asked on 08 Aug 2008, 01:56 PM
Hi,

I'm trying to open a RadWindow Server-Side. I'm using RadAjax.
I succeed in opening the RadWindow Once but then It never opens again.
I need to do it server-side because I have to do some code before the Window opens. How can I achieve this ?

Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="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>Page sans titre</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
  <telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
  <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
   <asp:Label ID="Label1" runat="server" />  
  </telerik:RadAjaxPanel>
    </div>
    </form>
</body>
</html>

Default.ascx.cs :

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
  CreateRadWindow();
    }
 protected void Button1_Click(object sender, EventArgs e)
 {
  Label1.Text = DateTime.Now.ToString();
 }
 private void CreateRadWindow()
 {
  RadWindow RadWindow1 = new RadWindow();
  RadWindow1.ID = "RadWindow1";
  RadWindow1.Behaviors = WindowBehaviors.Close | WindowBehaviors.Maximize | WindowBehaviors.Move | WindowBehaviors.Resize;
  RadWindow1.Title = "Title";
  RadWindow1.NavigateUrl = "http://www.google.com/";
  RadWindow1.Skin = "Vista";
  RadWindow1.OpenerElementID = Button1.ClientID;
  RadWindow1.ReloadOnShow = true;
  RadWindow1.Height = new Unit(480, UnitType.Pixel);
  RadWindow1.Width = new Unit(640, UnitType.Pixel);
  RadWindow1.Modal = true;
  RadWindow1.DestroyOnClose = true;
  RadWindowManager1.Windows.Add(RadWindow1);
 }
}

3 Answers, 1 is accepted

Sort by
0
Glen
Top achievements
Rank 1
answered on 08 Aug 2008, 04:16 PM
After Hours or research, I've foud a way to do what I needed. You can see the source below. But now I've got another problem. The Window appear each time there's a postback (click on button 2) after making it appearing the first time. How can I solve this problem ?

Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="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>Page sans titre</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
  <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
   <Windows>
    <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close, Maximize, Move, Resize" Title="Google" NavigateUrl="http://www.google.com" Skin="Vista" ReloadOnShow="true" Height="480" Width="640" Modal="true" />
   </Windows>
  </telerik:RadWindowManager>
     <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Open" />
     <asp:Button ID="Button2" runat="server" Text="PostBack" />
  <asp:Label ID="Label1" runat="server" />
  <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
   <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="Button1">
     <UpdatedControls>
      <telerik:AjaxUpdatedControl ControlID="Label1" />
     </UpdatedControls>
    </telerik:AjaxSetting>
    <telerik:AjaxSetting AjaxControlID="Button2">
     <UpdatedControls>
      <telerik:AjaxUpdatedControl ControlID="Label1" />
     </UpdatedControls>
    </telerik:AjaxSetting>
   </AjaxSettings>
  </telerik:RadAjaxManager>
    </div>
    </form>
</body>
</html>

Default.aspx.cs :

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
    }
 protected void Button1_Click(object sender, EventArgs e)
 {
  Label1.Text = DateTime.Now.ToString();
  RadAjaxManager1.ResponseScripts.Add(@"Sys.Application.add_load(function() 
        {radopen('http://www.google.com/', 'RadWindow1');})");  
 }
}

0
Sophy
Telerik team
answered on 11 Aug 2008, 03:35 PM
Hi Glen,

The best way to show RadWindow server-side is by setting its VisibleOnPageLoad property to true -RadWindow1.VisibleOnPageLoad = true;
However, please note that you will need to add the RadWindowManager in the UpdatedControls collection by Button1.
For your convenience I have attached a modified version of the page you have sent us which demonstrates the above suggestion.
The problem you experience in your current implementation is due to having registered a handler to the Application load event which you do not remove anywhere and therefore it is executed at every callback. You can resolve this problem if you remove the handler at Page_Load. You can see this resolution in the commented lines of the attached page. You should remove the RadWindowManager from the UpdatedControls collection by Button1 in this case.
We recommend using the first solution if you want to show the RadWindow server-side.
If you need further assistance, do contact us again.

Best regards,
Sophy
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Glen
Top achievements
Rank 1
answered on 12 Aug 2008, 12:20 PM
Thanks a lot for your help, your code works as I would !
Tags
Window
Asked by
Glen
Top achievements
Rank 1
Answers by
Glen
Top achievements
Rank 1
Sophy
Telerik team
Share this question
or