How to run telerik RadWindow from code behind

1110 picture 1110 · Dec 28, 2011 · Viewed 26.4k times · Source

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.

Answer

Jayesh Goyani picture Jayesh Goyani · Jan 6, 2012
 <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.