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

RadGrid popup disabled by combo box event function?

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 08 Nov 2012, 07:20 PM
Just had something odd happen. 

I have a fairly conventional RadGrid with a FormTemplate popup editor. This has been working normally.

On the FormTemplate is a RadComboBox and I've been trying to attach a function call to the OnClientLoad event with the eventual intent of doing some intialization to the popup.

This function is defined as follows:

function cbLoad(sender) {
    var curVal = sender.get_value();

    if (curVal == 3) {
       var editForm = $find("<%=RadGrid1.ClientID%>").get_masterTableView().get_editItems()[0].get_editFormItem();                                
     }
  }


It appears that the $find call is what's disabling the popup.  If I comment that out, the popup displays normally.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 13 Nov 2012, 03:00 PM
Hello Boris,

I suspect that the problem is related to a JS error on the page that prevents the popup from opening. One possible cause is the fact that OnClientLoad of the RadComboBox in this scenario fires before the GridCreated event of the RadGrid control. To workaround this limitation, you can execute the code referencing the grid with a slight delay. Here is a sample page that runs as expected on my end:


<%@ Page Language="C#" AutoEventWireup="true" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <script type="text/javascript">
        function cbLoad(sender, args)
        {
            var curVal = sender.get_value();
            setTimeout(function (curVal) { timeOutCheck() }, 100);
          
        }
        function timeOutCheck(curVal)
        {
            var editForm = $find("<%=RadGrid1.ClientID%>").get_masterTableView().get_editItems()[0].get_editFormItem();
            alert("Cur Val:" + curVal + "\nEdit Form:" + editForm);
        }
         
    </script>
    <script type="text/C#" runat="server">
        protected void Page_Init(object sender, EventArgs e)
        {
            RadGrid1.NeedDataSource += delegate(Object sen, GridNeedDataSourceEventArgs ar)
            {
                System.Data.DataTable table = new System.Data.DataTable();
                table.Columns.Add("Id", typeof(int));
                table.Columns.Add("Name");
                for (int i = 0; i < 10; i++)
                {
                    table.Rows.Add(i, "Col1 Row" + i);
                }
                RadGrid1.DataSource = table;
            };
        }
    </script>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False">
        <MasterTableView Width="100%" EditMode="PopUp">
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="Id" HeaderText="Id">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings ColumnNumber="2" EditFormType="Template">
                <FormTemplate>
                    <telerik:RadComboBox ID="AwardNameComboBox" runat="server" OnClientLoad="cbLoad">
                        <Items>
                            <telerik:RadComboBoxItem Text="1" />
                            <telerik:RadComboBoxItem Text="2" />
                            <telerik:RadComboBoxItem Text="3" />
                        </Items>
                    </telerik:RadComboBox>
                    <telerik:RadButton ID="radButtonInsertUpdate" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                    </telerik:RadButton>
                    <telerik:RadButton ID="radButtonCancelInsertUpdate" runat="server" Text="Cancel"
                        CausesValidation="false" CommandName="Cancel">
                    </telerik:RadButton>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
    </form>
</body>
</html>

I hope this helps.

Regards,
Martin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or