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

Close RadWindow server-side without postback

1 Answer 227 Views
Window
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 06 Feb 2012, 10:36 AM
Hello,

I need some help for showing and closing a RadWindow server-side without any postbacks.

The RadWindow is always added to the page (CreateChildControls):

m_overlayWindow = new RadWindow();
 m_overlayWindow.ID = "m_overlayWindow";
 m_overlayWindow.Behaviors = WindowBehaviors.None;
 m_overlayWindow.AutoSize = true;
 m_overlayWindow.VisibleOnPageLoad = false;
 Controls.Add(m_overlayWindow);
 
 RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
 AjaxSetting ajaxSetting1 = new AjaxSetting(m_ribbonBar.ID);
 ajaxSetting1.UpdatedControls.Add(new AjaxUpdatedControl(this.ID, LoadingPanel.ID) { UpdatePanelHeight = new Unit("100%") });
manager.AjaxSettings.Add(ajaxSetting1);

It should open in the click event handler of a RadRibbonBar;

m_overlayWindow.Modal = true;
m_overlayWindow.VisibleOnPageLoad = true;
          
RadButton buttonClose = new RadButton();
buttonClose.ID = "bclose";
buttonClose.Text = "Close";
buttonClose.Value = "close";
buttonClose.Click += new System.EventHandler(buttonClose_Click);
m_overlayWindow.ContentContainer.Controls.Add(buttonClose);
 
string script = "function f(){$find(\"" + m_overlayWindow.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
FmWebUtil.RegisterStartupScript(this.Page, "key", script, true);
RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
manager.AjaxSettings.AddAjaxSetting(m_overlayWindow, this, LoadingPanel);

Currently, the RadWindow only contains a simple button which should close the RadWindow:
void buttonClose_Click(object sender, System.EventArgs e)
      {
         m_overlayWindow.VisibleOnPageLoad = false;
      }

Note: The code which is executed when the RadRibbon bar's click event is handled is also executed after a postback (I save to the viewstate if I have to reopen the RadWindow).

My problem is: the RadWindow opens correctly, but clicking the close button does the first time I click nothing and the second time I click a full page reload. How do I have to open the RadWindow (and keep it open after a postback) and how do I close it without a complete page reload?

Thanks for your help!

Edit: Executing the javascript only when the RadWindow is opened from the click event (and not from another postback) resolves the problem that I have to click twice to close it. But closing still does a full page reload.

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 09 Feb 2012, 09:19 AM
Hi JP,

Generally, the RadWindow is entirely a client-side object and thus it cannot "survive" full postbacks. The best way to keep it shown on the page is to use AJAX - the rest of the page can be disposed when/if needed, but the RadWindow (and RadWindowManager) should generally be kept out of any update panels so that they are never disposed. If you do this you will be able to keep your RadWindow opened until you decide to close it via code (or the user clicks its close button).

I strongly suggest you examine the following article on using RadWindow with AJAX: http://www.telerik.com/help/aspnet-ajax/radwindow-ajaxifying.html. It explains how and why AJAX does not work in its content template if configured improperly. Said shortly - put an update panel inside the ContentTemplate to ajaxify it correctly.

Now, on closing the RadWindow from your button's click - assuming you hava ajaxified the content template correclty the best approach is to inject the script that will call the close() method of the RadWindow in the same manner you call show(). Doing so will also spare the need of using the VisibleOnPageLoad properly, which is not the best way to open a RadWindow from the server.


Kind regards,
Marin
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Window
Asked by
JP
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or