OnUpdateCommand

3 posts, 0 answers
  1. Bruno
    Bruno avatar
    20 posts
    Member since:
    Feb 2012

    Posted 13 Mar 2012 Link to this post

    Hello, i have a project radGrid editable with user control, similar to that example :
    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

    My problem is, when i click on update button on my userControl the event on my page which contains my update code, will never be fired.
    i want this event above, be fired when i click on the update button on my user control.
    protected void rgGrid_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
     
     
        //Prepare new row to add it in the DataSource
        DataRow[] changedRows = this.GridSource.Select("codigo = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["codigo"]);
     
        if (changedRows.Length != 1)
        {
            rgGrid.Controls.Add(new LiteralControl("Unable to locate the Employee for updating."));
            e.Canceled = true;
            return;
        }
     
        //Update new values
        Hashtable newValues = new Hashtable();
     
        newValues["codigo"] = (userControl.FindControl("txtCodigo") as TextBox).Text;
        newValues["descricao"] = (userControl.FindControl("txtDescricao") as TextBox).Text;
        changedRows[0].BeginEdit();
        try
        {
            foreach (DictionaryEntry entry in newValues)
            {
                changedRows[0][(string)entry.Key] = entry.Value;
            }
            changedRows[0].EndEdit();
            this.GridSource.AcceptChanges();
        }
        catch (Exception ex)
        {
            changedRows[0].CancelEdit();
            Window.RadAlert("Erro!", 350, 250, "Mensagem", null);
            e.Canceled = true;
        }
    }

    user control code
    private object _dataItem = null;
     
            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
            public object DataItem
            {
                get
                {
                    return this._dataItem;
                }
                set
                {
                    this._dataItem = value;
                }
            }
     
            protected void btnUpdate_Click(object sender, EventArgs e)
            {
                 // should i do something here or what?
            }


    Please help me.
    Thankz in advance!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Mar 2012 Link to this post

    Hello,

    Please make sure that you have assigned the commandName for the Update button in the usercontrol edit form for the event bubbling.
    It is not actually possible to find the real issue from the given code. Please provide the entire code for further assistance.

    -Shinu.
  3. Judith
    Judith avatar
    1 posts
    Member since:
    Jul 2018

    Posted 20 Jul 2018 Link to this post

    This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. 
Back to Top