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

How to open Rad Window from Codebehind in C#?

4 Answers 1120 Views
Window
This is a migrated thread and some comments may be shown as answers.
Aravind S
Top achievements
Rank 1
Aravind S asked on 26 Mar 2010, 12:48 AM
Hi, Can you please:
Am using 2 radio butons. (Edit and View).
When the Radio button View is selected the Controls are Disabled. When in Edot mode Control are Enable.
Among the Control we have RadEditor. When user selects Edit Radio Button , the RadEditor is get Enlagred the the Tools (FontName,Size etc) VERTICALLY.Its Enlarging Vertically for the 2 time edit Clcik.

Please find attached Images.

Can you Please help.


4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Mar 2010, 06:35 AM

Hello Aravind,

You can open the RadWindow from the server by setting its VisibleOnPageLoad property to true.

C#:

 
    protected void Button1_Click(object sender, EventArgs e)   
    {   
        RadWindowManager windowManager = new RadWindowManager();   
        RadWindow widnow1 = new RadWindow();   
        // Set the window properties   
        widnow1.NavigateUrl = "Window1.aspx";   
        widnow1.ID = "RadWindow1";   
        widnow1.VisibleOnPageLoad = true// Set this property to True for showing window from code   
        windowManager.Windows.Add(widnow1);   
        this.form1.Controls.Add(widnow1);   
    }  

More information on the subject is available here: Setting Server-Side Properties

-Shinu.

0
Aravind S
Top achievements
Rank 1
answered on 27 Mar 2010, 01:01 AM
Hi, how to Popup a Window - window.showModalDialog(URL,"","") when user click EDIT button of RADGRID from CODEBEHIND in C#?
I want to Open that Pop Up Window in ItemCommand Event of RADGRID?
0
Aravind S
Top achievements
Rank 1
answered on 27 Mar 2010, 01:05 AM
Hi Shinu, Thanks. But now requirement Changed!!!!!!

I want to open a Popup Window NOT RAD WINDOW, its like showModalDialog(URL,"",""), This oopen shold open in ITEMCOMMAND of RAD GRID Edit Button Click.
Can you help in this?
0
Shinu
Top achievements
Rank 2
answered on 02 Aug 2013, 12:20 PM
Hi Aravind,

The best option is to use the ItemCreated event of the RadGrid instead of using the ItemCommand event. Please have a look into the following code I tried which works fine at my end.

ASPX:
<telerik:RadGrid OnItemCreated="RadGrid1_ItemCreated" ID="RadGrid1" runat="server"
    AllowPaging="True" Width="97%" DataSourceID="SqlDataSource1" AutoGenerateEditColumn="true"
    OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound">
    <PagerStyle Mode="NumericPages"></PagerStyle>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="EmployeeID" ClientDataKeyNames="EmployeeID"
        Width="100%" CommandItemDisplay="Top" PageSize="5">
        <Columns>
            <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" ReadOnly="True"
                SortExpression="EmployeeID" UniqueName="EmployeeID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName"
                UniqueName="FirstName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" SortExpression="LastName"
                UniqueName="LastName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Title" HeaderText="Title" SortExpression="Title"
                UniqueName="Title">
            </telerik:GridBoundColumn>
        </Columns>
        <CommandItemTemplate>
            <a href="#" onclick="return ShowInsertForm();">Add New Record</a>
        </CommandItemTemplate>
    </MasterTableView>
</telerik:RadGrid>


C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item=(GridDataItem)e.Item;
        LinkButton lnk= (LinkButton)item["AutoGeneratedEditColumn"].Controls[0];
        lnk.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"], e.Item.ItemIndex);
    }
}

JavaScript:
<script type="text/javascript">
    function ShowEditForm(id, rowIndex) {
        var grid = $find("<%= RadGrid1.ClientID %>");
        var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
        grid.get_masterTableView().selectItem(rowControl, true);
        window.open("EditFormcs.aspx?EmployeeID=" + id, "WindowPopup", "scrollbars=1, width=400px, height=400px");
        return false;
    }
</script>

In the browsers popup window I am opening the Edit form. Here is the mark-up and JavaScript.

ASPX:
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Vista" DecoratedControls="All" />
<asp:DetailsView ID="DetailsView1" DataKeyNames="EmployeeID" runat="server" AutoGenerateRows="False"
    DataSourceID="SqlDataSource1" Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand"
    BorderWidth="0" CellPadding="0" CellSpacing="7" GridLines="None" OnItemUpdating="DetailsView1_ItemUpdating">
    <Fields>
        <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
        <asp:CommandField ShowEditButton="true" ButtonType="Button" />
        <asp:CommandField ShowCancelButton="true" ButtonType="Button" CancelText="CancelText" />
    </Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
    InsertCommand="INSERT INTO [Employees] ([LastName], [FirstName], [Title]) VALUES (@LastName, @FirstName, @Title)"
    SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title] FROM [Employees] WHERE ([EmployeeID] = @EmployeeID)"
    UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, [FirstName] = @FirstName, [Title] = @Title WHERE [EmployeeID] = @EmployeeID">
    <InsertParameters>
        <asp:Parameter Name="LastName" Type="String" DefaultValue="" ConvertEmptyStringToNull="false" />
        <asp:Parameter Name="FirstName" Type="String" DefaultValue="" ConvertEmptyStringToNull="false" />
        <asp:Parameter Name="Title" Type="String" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="LastName" Type="String" DefaultValue="" ConvertEmptyStringToNull="false" />
        <asp:Parameter Name="FirstName" Type="String" DefaultValue="" ConvertEmptyStringToNull="false" />
        <asp:Parameter Name="Title" Type="String" />
        <asp:Parameter Name="EmployeeID" Type="Int32" />
    </UpdateParameters>
    <SelectParameters>
        <asp:QueryStringParameter Name="EmployeeID" QueryStringField="EmployeeID" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

C#:
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
 
    if (Request.QueryString["employeeid"] == null)
    {
        DetailsView1.DefaultMode = DetailsViewMode.Insert;
    }
    else
    {
        DetailsView1.DefaultMode = DetailsViewMode.Edit;
    }
    this.Page.Title = "Editing record";
}
 
protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
    if (e.CommandName == "Update")
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
    }
    else
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true);
    }
}

JavaScript:
<script type="text/javascript">
    function CloseAndRebind(args) {
        opener.location.reload();
        window.close();
    }
 
    function CancelEdit() {
        window.close();
    }
</script>

Thanks,
Shinu.
Tags
Window
Asked by
Aravind S
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Aravind S
Top achievements
Rank 1
Share this question
or