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

Opening RadWindow from the server

0 Answers 1469 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Telerik Admin
Top achievements
Rank 1
Iron
Telerik Admin asked on 23 Aug 2011, 11:09 AM

The RadWindow is a client-side object – its UI is created when it is first shown and this is the point when the CSS and scripts are loaded as well. This means that it should be used on the client via JavaScript, yet it turns out that it is a very common scenario that the developer wishes to initiate the RadWindow’s showing from the code-behind.


The VisibleOnPageLoad property should not be used for this purpose. It is a behavior property which will result in the RadWindow opening every time the page is post back.

Quite often the VisibleOnPageLoad property gets set to true while the intention is that the RadWindow should only show once. Doing so will result in the RadWindow reopening if a postback is initiated from another element from the page, which is rarely the desired behavior. Also, this approach will not work in case this happens in an AJAX request and the RadWindow is not included in the partial page update.

There are several ways to work around this:
1) Register a JavaScript function from the server-side and do not use the VisibleOnPageLoad property, for example:

<telerik:RadWindow runat="server" ID="RadWindow1" NavigateUrl="http://google.com/"></telerik:RadWindow>
<asp:Button ID="Button1" Text="open the RadWindow from the server" runat="server" OnClick="Button1_Click" />
C#
protected void Button1_Click(object sender, EventArgs e) 
    //business logic goes here 
   
    string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); 
}


VB:
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click 
    'business logic goes here 
   
    Dim script As String = "function f(){$find(""" + RadWindow1.ClientID + """).show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, True
End Sub


2) Reset the VisibleOnPageLoad property to false with code when suitable, depending on the particular scenario

3) Set EnableViewState to false for the RadWindowManager that contains the desired RadWindows

Tags
Window
Asked by
Telerik Admin
Top achievements
Rank 1
Iron
Share this question
or