cancel button working by clicking two times when i am useing e.cancel true in grid_UpdateCommand

1 posts, 0 answers
  1. Manish
    Manish avatar
    64 posts
    Member since:
    Jul 2011

    Posted 28 Dec 2012 Link to this post

    Hi,
    I am inserting data in grid but i want to keep grid in edit mode if validation false. For that i am using e.canceled=true in else part.
    But after that cancel is not working in one time i have to click it two times. Please help
     
     protected void rgBankAccount_UpdateCommand(object source, GridCommandEventArgs e)
            {
                if (ViewState["CommandName"] != null)
                    strCommandName = ViewState["CommandName"].ToString();
                if (e.Item.OwnerTableView.Name == "Master")
                {
                    UserControl ParentUserControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
                    TextBox txtAccount = ParentUserControl.FindControl("txtAccount") as TextBox;
                   //Label lblError = ParentUserControl.FindControl("lblError") as Label;
                    RadDatePicker rdpAsof = ParentUserControl.FindControl("rdpAsof") as RadDatePicker;
                    RadNumericTextBox RNTXTAccountNumber = ParentUserControl.FindControl("RNTXTAccountNumber") as RadNumericTextBox;
                    RadNumericTextBox RNTXTBeginningBalance = ParentUserControl.FindControl("RNTXTBeginningBalance") as RadNumericTextBox;
                    if (strCommandName == "Update")
                    {
                        int AccountID = 0;
                        if (ViewState["AccountID"] != null)
                            AccountID = Convert.ToInt32(ViewState["AccountID"].ToString());
                        int AccountCount = objGetData.GetAccountExist(txtAccount.Text, AccountID, GroupID);
                        if (AccountCount == 0)
                        {
                            objUpdateData.UpdateBankAccount(AccountID, rdpAsof.SelectedDate.ToString(), txtAccount.Text,                        RNTXTAccountNumber.Text, Convert.ToDouble(RNTXTBeginningBalance.Text));
                            ViewState["AccountID"] = null;
                            lblError.Visible = false;
                         
                        }
                        else
                        {
                            lblError.Visible = true;
                            lblError.Text = "Please select another name";
                                                 e.Canceled = true; *********************************** //// I have used it here
                        }
                    }
                    else
                    {
                        int AccountCount = objGetData.GetAccountExist(txtAccount.Text, 0, GroupID);
                        if (AccountCount == 0)
                        {
                        objAddData.AddBankAccount(rdpAsof.SelectedDate.ToString(), txtAccount.Text, RNTXTAccountNumber.Text, Convert.ToDouble(RNTXTBeginningBalance.Text), GroupID);
                        lblError.Visible = false;
                        }
                        else
                        {
                            lblError.Visible = true;
                            lblError.Text = "Please select another name";
                           e.Canceled = true; *********************************** //// I have used it here
                        }
                    }
                }
            }

    Thanks
    Manish
Back to Top