1

I have a check box, drop down list and required field validtor in RadGrid. I want to enable disable required filed validator for the drop down upon check box selection. Now the below Java script code does enable and disable the required filed validator on edit mode.

But when I click rad grid edit mode update button (check box is un-checked and drop down box selected value also empty ("") it waits little while (probably doing a post back) and fire the required field validator again.

Any idea why it behaving like that. Help appreciate.

I got the control access part from below link. Accessing Telerik RadGrid edit mode from javascript

my Rad grid markup:

 <EditItemTemplate>
<asp:CheckBox ID="chkConfigurable" runat="server" Checked='<%# Bind("Configurable") %>'
  </EditItemTemplate>  

This is my java script code:

// Enbable or disable the required field validator depend on check box selection

    function EnableDisbaleConfigRfv(chkbx) {

        var grid = $find("<%=rgItems.ClientID %>");
        var masterTable = grid.get_masterTableView();
        // get the required field validator id from grid
        var rfv = $telerik.$(masterTable.get_element()).find('[id*="rfvddlConfigTeam"]')[0];

        // enable disable validator
        if (chkbx) {
            ValidatorEnable(rfv, true);
            ValidatorUpdateDisplay(rfv); // this one added after reading some posts but no luck.


        } else {
            ValidatorEnable(rfv, false);

        }
    }
Community
  • 1
  • 1
mwinston
  • 35
  • 1
  • 6

1 Answers1

1

Please try with below code snippet.

js

 function ValidateValidation(cmb, chk, lbl) {

            cmb = $find(cmb);
            chk = document.getElementById(chk);
            lbl = document.getElementById(lbl);
            if (chk.checked) {
                if (cmb.get_value() != null && cmb.get_value() != "" && cmb.get_selectedIndex() >= 0) {
                    debugger;
                    return true;
                }
                else {
                    lbl.style.display = '';
                    return false;
                }
            }
            else {
                lbl.style.display = 'none';
                return true;
            }


        }

aspx

 <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                        <telerik:RadComboBox ID="RadComboBox1" runat="server">
                            <Items>
                            </Items>
                        </telerik:RadComboBox>
                        <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="your messege" Style="display: none;"></asp:Label>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>

aspx.cs

  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = e.Item as GridEditableItem;
        CheckBox CheckBox1 = item.FindControl("CheckBox1") as CheckBox;
        Label Label1 = item.FindControl("Label1") as Label;
        RadComboBox RadComboBox1 = item.FindControl("RadComboBox1") as RadComboBox;

        (item.FindControl("UpdateButton") as LinkButton).Attributes.Add("onclick", "return ValidateValidation('" + RadComboBox1.ClientID + "','" + CheckBox1.ClientID + "','" + Label1.ClientID + "');");

    }
}
Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50