How to run telerik RadWindow from code behind

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.


 <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.


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.


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.

链接地址: http://www.djcxy.com/p/56930.html

上一篇: 具有字符串分隔符的Java CSV分析器(多

下一篇: 如何从后面的代码运行telerik RadWindow