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

[Solved] loading radWindow from Codebehind

8 Answers 970 Views
Window
This is a migrated thread and some comments may be shown as answers.
jai
Top achievements
Rank 1
jai asked on 06 Feb 2008, 06:26 PM
Hi,

Im using masterpage and Prometheus controls in my project. On Button Click i need to open radwindow from codebehind, the code what im having is working fine with RadControls Q3 but not for Prometheus Control. Can anyone guide me to the issue.

Master page.

<

telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>

Content Page:

On Button Click-

string windowScript = "<script language=javascript>window.radopen('RadGrid.aspx')</script>";
ClientScript.RegisterClientScriptBlock(Page.GetType(),
"LoginWindowScript", windowScript);

-------------
Looking forward of ur response

Regards
Jai

8 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 07 Feb 2008, 02:12 PM
Hi jai,

The code that you posted is correct and should work as expected in a common scenario. I am not sure what is causing the problem on your side but if you open a ticket and send me a small sample project where the problem can be reproduced, I will check it right away.

Please note that you can also open the RadWindow directly from the codebehind, without calling a JavaScript function that will call radopen(). More information on how to do this and a code sample is available here.



Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sean Marchiafava
Top achievements
Rank 1
answered on 07 Feb 2008, 03:15 PM

I have a grid with a button column that will open a window from server side. I have followed all examples and various methods and if the grid is ajaxified it will not work. If ajax is disabled on the grid the client side function fires but an error is returned "can't open site, operation aborted".

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %> 
<%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %> 
<%@ Register Assembly="RadWindow.Net2" Namespace="Telerik.WebControls" TagPrefix="radW" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!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>Untitled Page</title> 
</head> 
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
 
    <script type="text/javascript" language="javascript">  
          
        function ShowDialog(url,title,width,height,dest)  
        {     
              
            var win = GetRadWindowManager().GetWindowByName("modal");  
            win.SetUrl(url);        
            win.SetSize(width, height);     
            win.Show();    
        }   
           
 
          
        function ViewDocument()  
        {   
                //alert('Server side initiated');  
               ShowDialog('/Default2.aspx',  
               'View Document',400,500,"self");      
          
        }                
     
 
    </script> 
</telerik:RadCodeBlock> 
<body>     
      
    <form id="form1" runat="server">  
        <radA:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        </radA:RadAjaxManager> 
        <radW:RadWindowManager ID="RadWindowManager1" runat="server">  
        <Windows> 
            <radW:RadWindow id="modal"   
                Modal = "True"             
                Runat="server"   
                Behavior="Close, Maximize" Left="" NavigateUrl="" SkinsPath="~/RadControls/Window/Skins" Title="" Top="" 
                > 
            </radW:RadWindow> 
        </Windows> 
        </radW:RadWindowManager> 
        <radG:RadGrid ID="RadGrid1" runat="server" GridLines="None" OnItemCommand="RadGrid1_ItemCommand1" 
            OnNeedDataSource="RadGrid1_NeedDataSource1">  
            <MasterTableView> 
                <Columns> 
                    <radG:GridButtonColumn CommandArgument="View" CommandName="View" Text="View" UniqueName="column">  
                    </radG:GridButtonColumn> 
                </Columns> 
                <ExpandCollapseColumn Visible="False">  
                    <HeaderStyle Width="19px" /> 
                </ExpandCollapseColumn> 
                <RowIndicatorColumn Visible="False">  
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
            </MasterTableView> 
        </radG:RadGrid> 
    </form> 
</body> 
</html> 
 
 
protected void RadGrid1_NeedDataSource1(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)  
    {  
        ArrayList list = new ArrayList();  
        list.Add("string1");  
        list.Add("string2");  
        list.Add("string3");  
        RadGrid1.DataSource = list;  
    }  
 
    protected void RadGrid1_ItemCommand1(object source, Telerik.WebControls.GridCommandEventArgs e)  
    {  
        if (e.CommandName == "View")  
        {  
              
            ClientScript.RegisterStartupScript(this.GetType(), "Fax""<script language='javascript'>ViewDocument();</script>");  
 
        }  
    } 
0
Georgi Tunev
Telerik team
answered on 08 Feb 2008, 01:42 PM
Hi Sean,

You will make sure that the page is fully loaded before calling your script. For example you can fire it in the page's onload event:
protected void RadGrid1_ItemCommand1(object source, Telerik.WebControls.GridCommandEventArgs e) 
    if (e.CommandName == "View"
    { 
 
        ClientScript.RegisterStartupScript(this.GetType(), "Fax""<script language='javascript'>window.onload = ViewDocument;</script>"); 
 
    } 
}  
 


By the way you can also set up and open the RadWindow directly from the server by using its Server-Side API



Sincerely yours,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sean Marchiafava
Top achievements
Rank 1
answered on 08 Feb 2008, 06:20 PM
That doesn't work either. Like I said the grid is ajaxified and never causes a window.onload.  Could you provide a sample of a grid with a simple button column that launches a window from server side registered script that works? Without the grid causing a full postback the script never gets executed because the only part of the page being rendered again is the grid itself.
0
Sean Marchiafava
Top achievements
Rank 1
answered on 08 Feb 2008, 07:08 PM
"By the way you can also set up and open the RadWindow directly from the server by using its Server-Side API"

Not without a full postback of the page you can't. Like I said before, I can make all these methods work, pure client-side, server side registerstartupscript, and pure server side manipulation of the windowmanager, but not from an ajaxified postback from a control such as a grid button column.


0
Jason
Top achievements
Rank 1
answered on 08 Feb 2008, 08:49 PM
Hi Georgi,

I am having the same problem with this control.  I have actually tried two methods of loading the control dynamically:

1.  I have a function called "LoadControlWindow" which basically takes in the 
     WindowManager and some window properties, creates a new window,
     and adds it to the window manager.  In the old classic ASP .NET control
     set, this was not a problem.  But, with the new Prometheus controls, the
     window will not load.  Further, with this method, the new control set causes
     the calling page to go through it's life cycle 2-3 times, whereas this was
     not an issue with the old control set.

2.  I did just as jai did, but I call the AJAX 
     ScriptManager.RegisterStartupScript.  I verified that my script was
     injected into the page, and again, the Window does not load.

Here is some sample code that I used for the first method:

My LoadControlWindow function:

 
Public Sub LoadControlWindow(ByVal title As String, ByVal URL As String, ByRef windowManager As Telerik.Web.UI.RadWindowManager, Optional ByVal windowID As String = "APSControlWindow", Optional ByVal isModal As Boolean = True, Optional ByVal width As String = "320px", Optional ByVal height As String = "240px", Optional ByVal options As TelerikTelerik.Web.UI.WindowBehaviors = Telerik.Web.UI.WindowBehaviors.Default, Optional ByVal backColor As String = "#FFFFF", Optional ByVal OnClientCloseEvt As String = "", Optional ByVal initialBehavior As TelerikTelerik.Web.UI.WindowBehaviors = Telerik.Web.UI.WindowBehaviors.Default)  
 
        ' Create a new window  
        Dim newWindow As New Telerik.Web.UI.RadWindow()  
        newWindow.ID = windowID 
        newWindow.Title = title 
        newWindow.NavigateUrl = URL 
        newWindow.Width = Unit.Parse(width)  
        newWindow.Height = Unit.Parse(height)  
        newWindow.VisibleStatusbar = False 
        newWindow.VisibleOnPageLoad = True 
        newWindow.DestroyOnClose = True 
        If (initialBehavior <> Telerik.Web.UI.WindowBehaviors.Default) Then  
            newWindow.InitialBehaviors = initialBehavior 
        End If  
        newWindow.Behaviors = options 
        newWindow.Modal = isModal 
        newWindow.BackColor = System.Drawing.ColorTranslator.FromHtml(backColor)  
        newWindow.OnClientClose = OnClientCloseEvt 
 
        ' Add the newly created window to the windows collection  
        windowManager.Windows.Add(newWindow)  
    End Sub  
 
 

Then, I use this code in the page load event as follows:

LoadControlWindow("My Title", "myPageLoc.aspx", winMgr, "winName", width:="500px", height:="500px", OnClientCloseEvt:="DoSomething();")

Again, either way I try to invoke the window to display, nothing happens.  However, with the old controls, I had no issues with this.  Any help would be greatly appreciated.


Thanks,
Jason

0
Sean Marchiafava
Top achievements
Rank 1
answered on 11 Feb 2008, 06:37 PM
Bump..
0
Georgi Tunev
Telerik team
answered on 12 Feb 2008, 04:52 PM
Hello guys,

Jason, I tried your code (I've replaced TelerikTelerik.Web.UI... with Telerik.Web.UI.. to run it)  and it worked as expected:
in the aspx:
<form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"
    </asp:ScriptManager> 
 
    <script type="text/javascript"
        function DoSomething(){} 
    </script> 
 
    <telerik:RadWindowManager ID="winMgr" runat="server"
    </telerik:RadWindowManager> 
</form> 

And in the codebehind:
    Public Sub LoadControlWindow(ByVal title As StringByVal URL As StringByRef windowManager As Telerik.Web.UI.RadWindowManager, Optional ByVal windowID As String = "APSControlWindow"Optional ByVal isModal As Boolean = TrueOptional ByVal width As String = "320px"Optional ByVal height As String = "240px"Optional ByVal options As Telerik.Web.UI.WindowBehaviors = Telerik.Web.UI.WindowBehaviors.DefaultOptional ByVal backColor As String = "#FFFFF"Optional ByVal OnClientCloseEvt As String = ""Optional ByVal initialBehavior As Telerik.Web.UI.WindowBehaviors = Telerik.Web.UI.WindowBehaviors.Default
 
        ' Create a new window   
        Dim newWindow As New Telerik.Web.UI.RadWindow() 
        newWindow.ID = windowID 
        newWindow.Title = title 
        newWindow.NavigateUrl = URL 
        newWindow.Width = Unit.Parse(width) 
        newWindow.Height = Unit.Parse(height) 
        newWindow.VisibleStatusbar = False 
        newWindow.VisibleOnPageLoad = True 
        newWindow.DestroyOnClose = True 
        If (initialBehavior <> Telerik.Web.UI.WindowBehaviors.DefaultThen 
            newWindow.InitialBehaviors = initialBehavior 
        End If 
        newWindow.Behaviors = options 
        newWindow.Modal = isModal 
        newWindow.BackColor = System.Drawing.ColorTranslator.FromHtml(backColor) 
        newWindow.OnClientClose = OnClientCloseEvt 
 
        ' Add the newly created window to the windows collection   
        windowManager.Windows.Add(newWindow) 
    End Sub 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
 
        LoadControlWindow("My Title""myPageLoc.aspx", winMgr, "winName", width:="500px", height:="500px", OnClientCloseEvt:="DoSomething"
 
    End Sub 

Can you please fix the paramethers in the LoadControlWindow() function and let me know if this fixes the problem on your side? If it doesn't please open a support ticket and send me a small sample project where the problem can be reproduced. I will check it and do my best to help.




Sean, to call the Javascript code in this case, you need to set the RadAjaxManager to ajaxify the RadGrid control and then call the script by adding it in the RadAjaxManager's ResponseScripts collection.

e.g.
<radA:RadAjaxManager ID="RadAjaxManager1" runat="server">   
    <AjaxSettings> 
        <radA:AjaxSetting AjaxControlID="RadGrid1"
            <UpdatedControls> 
                <radA:AjaxUpdatedControl ControlID="RadGrid1" /> 
            </UpdatedControls> 
        </radA:AjaxSetting> 
    </AjaxSettings> 
</radA:RadAjaxManager>  

and in the codebehind:
protected void RadGrid1_ItemCommand1(object source, Telerik.WebControls.GridCommandEventArgs e) 
    if (e.CommandName == "View"
    { 
 
        RadAjaxManager1.ResponseScripts.Add("ViewDocument()"); 
    } 
}  



Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Window
Asked by
jai
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Sean Marchiafava
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or