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

Rad Grid Insert/Update Command not Firing After disabeling validation

1 Answer 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nisha
Top achievements
Rank 1
Nisha asked on 10 Nov 2011, 06:37 AM
Hello,

I have used rad grid with insert , update option using edit form template.While Add/Edit time Depending on Radio Button Selection I need to Enable , Disable Validation. Insert , Update option works perfect when validation are enable but when i am selecting option which is disabling my validation then by clicking on Insert , Update button my insertcommand and updatecommand are not working. By clicking on insert or update button it direct comes to itemcommand event not on insert or update command.

Any Idea why rad grid insert , update command not working after disabling validation?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Nov 2011, 10:20 AM
Hello,

Sorry but i am not able to reproduce the issue.
Please check below code snippet.

<asp:RadioButton  ID="RadioButton1" runat="server" GroupName="RadioButton" Checked="true" Text="EnableValidation" />
    <asp:RadioButton  ID="RadioButton2" runat="server" GroupName="RadioButton" Text="DisableValidation" />
    <telerik:RadGrid ID="RadGrid3" runat="server" AutoGenerateColumns="false" OnInsertCommand="RadGrid3_InsertCommand"
        OnNeedDataSource="RadGrid3_NeedDataSource1"
        OnUpdateCommand="RadGrid3_UpdateCommand"
        onitemdatabound="RadGrid3_ItemDataBound">
        <MasterTableView EditMode="EditForms" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn DataField="ID1" HeaderText="ID1" UniqueName="ID1">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ID2" HeaderText="ID2" UniqueName="ID2">
                </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ID1") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                        ErrorMessage="******************"></asp:RequiredFieldValidator>
                    <br />
                    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                    </asp:Button
                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                        CommandName="Cancel"></asp:Button>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>

protected void RadGrid3_NeedDataSource1(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
                new { ID1 = 1, ID2 = 2},
                new { ID1 = 4, ID2 = 5}
                
            };
        RadGrid3.DataSource = data;
    }
    protected void RadGrid3_InsertCommand(object sender, GridCommandEventArgs e)
    {
 
    }
    protected void RadGrid3_UpdateCommand(object sender, GridCommandEventArgs e)
    {
 
    }
    protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if(e.Item.IsInEditMode && e.Item is GridEditFormItem)
        {
            GridEditFormItem item = e.Item as GridEditFormItem;
            if (RadioButton2.Checked)
            {
                (item.FindControl("RequiredFieldValidator1") as RequiredFieldValidator).Enabled = false;
            }
            else
            {
                (item.FindControl("RequiredFieldValidator1") as RequiredFieldValidator).Enabled = true;
            }
        }
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Nisha
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or