How to run telerik RadWindow from code behind
Asked Answered
F

3

7

I am trying to run telerik rad window from code behind. But I have some issues. I don't know is it important but I am trying to run rad window from button clicked in edit mode from rad grid.

RadWindow window1 = new RadWindow();
window1.NavigateUrl = "http://www.google.com";
window1.VisibleOnPageLoad = true;
window1.ID = "RadWindow1";
window1.Width = 500;
window1.Height = 300;
window1.VisibleOnPageLoad = true;    
rwm_WindowManager.Windows.Add(window1);

On the page I also have RadAjaxManager and rwm_WindowManager I put in RadAjaxPanel.
Problem is that this rad window never shows up. There are no errors but no rad window also.

Fleck answered 28/12, 2011 at 9:49 Comment(2)
can you show the code with the RadAjaxPanel and the WindowManager? Maybe the Panel is not visible at all. Are you sure that the shown code is called when clicking the button?Cockpit
please, could you try to change RadAjaxPanel to ordinary asp:Panel and check if the RadWindow shows up?Brinson
L
3
 <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        </telerik:RadWindowManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
            OnItemCommand="RadGrid1_ItemCommand">
            <MasterTableView DataKeyNames="ID">
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Button ID="Button1" Text="Open window" CommandName="OpenWindow" runat="server" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>

........................

 protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
            new { ID = "1", Name ="Name11",ParentID = "0"},
            new { ID = "2", Name ="Name11",ParentID = "0"},
            new { ID = "3", Name ="Name11",ParentID = "0"},
            new { ID = "4", Name ="Name11",ParentID = "0"}
        };
    RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "OpenWindow")
    {
        //RadWindowManager
        RadWindow window1 = new RadWindow();
        window1.NavigateUrl = "http://www.google.com";
        window1.VisibleOnPageLoad = true;
        window1.ID = "RadWindow1";
        window1.Width = 500;
        window1.Height = 300;
        RadWindowManager1.Windows.Add(window1);

    }
}

put your RadWindowManager inside RadAjaxPanel.

Locus answered 6/1, 2012 at 6:11 Comment(2)
Oh, thank you very much. My problem was that I omitted RadAjaxManager (there was only RadAjaxPanel). Consider an user control with RadAjaxPanel which I want open a RadWindow from and this control is used on many pages. Each page can contain many such controls but one page can contain only one RadWindowManager. Is it possible to achieve such scenario?Brinson
If the RadWindowManager is omitted and the RadWindow is directly added into RadAjaxPanel, everything works fine. I don't get it.Brinson
P
1

I just had a similar issue. I resolved it like so:

RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(String.Format("$find('{0}').show();", window1.ClientID));

My applications use RadAjax which makes the VisibleOnPageLoad property problematic, so I avoid it altogether.

Puli answered 2/8, 2013 at 16:33 Comment(0)
R
0

Take a look here: How to refresh parent page grid when close radwindow? and examine the links from my answer. The approach is much cleaner and will spare you a couple of unnecessary postbacks.

Recurrent answered 6/8, 2013 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.