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

OnInsertCommand and OnUpdateCommand not firing for grid

2 Answers 294 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 12 Sep 2008, 12:40 PM
The onupdatecommand and oninsertcommand no longer fire for my grids.  I also get and error that I need a scriptmanager, never got this before.  The ondeletecommand does fire.There was a recent change to the master file, only in format (images etc.).  Any ideas what I should do?

<%@ Page Language="C#" MasterPageFile="~/Masters/Site.Master" AutoEventWireup="true" 
    CodeBehind="Nouns.aspx.cs" Inherits="MIDI_Internal.Lookups.NSNs.Nouns" Title="MIDI - Manage Nouns" %> 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    Namespace="System.Web.UI" TagPrefix="asp" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="cphPageTitle" runat="server">  
    Manage Nouns  
</asp:Content> 
<asp:Content ID="Content3" ContentPlaceHolderID="cphMainBody" runat="server">  
 
<script type="text/javascript">  
 
 
function KeyPressed(sender, eventArgs)  
 
 {  
    //alert(eventArgs.get_keyCode());  
    if (eventArgs.get_keyCode()==13)  
    {  
      
        //alert('Cancel me');  
        //selectedRow = -1;  
        eventArgs.set_cancel(true);  
        //FireCommandEvent ("Update", GridCommandEventArgs);  
        //return false;  
          
 
    }  
 }  
 
</script> 
 
    <asp:ObjectDataSource ID="ObjectDataSourceLookup" runat="server"   
        DeleteMethod="Delete" InsertMethod="Insert"   
        SelectMethod="GetDT" UpdateMethod="Update" 
        TypeName="MIDI_Internal.BLL_Noun" > 
        <DeleteParameters> 
            <asp:Parameter Name="NounID" Type="Int32" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="NounID" Type="Int32" /> 
            <asp:Parameter Name="Noun" Type="String" /> 
        </UpdateParameters> 
        <SelectParameters> 
            <asp:Parameter Name="NounID" Type="Int32" /> 
        </SelectParameters> 
        <InsertParameters> 
            <asp:Parameter Name="Noun" Type="String" /> 
        </InsertParameters> 
    </asp:ObjectDataSource> 
 
    <telerik:RadGrid ID="RadGridLookup" runat="server" AllowFilteringByColumn="True" 
        AllowPaging="True" AllowSorting="True" GridLines="None" Skin="Mac"   
        EnableAJAX="True" width="60%" AllowAutomaticDeletes="true" 
        AllowAutomaticInserts="true" AllowAutomaticUpdates="true"   
        PagerStyle-Mode="NextPrevNumericAndAdvanced" ClientSettings-Resizing-AllowColumnResize="true" 
        DataSourceID="ObjectDataSourceLookup"   
        OnItemDeleted="RadGridLookup_ItemDeleted" OnItemDataBound="RadGridLookup_ItemDataBound" 
        OnDeleteCommand="RadGridLookup_DeleteCommand" OnItemInserted="RadGridLookup_ItemInserted" 
        OnInit="RadGridLookup_Init" OnColumnCreated="RadGridLookup_ColumnCreated"   
        OnInsertCommand="RadGridLookup_InsertCommand"   
        OnItemUpdated="RadGridLookup_ItemUpdated"   
        OnUpdateCommand="RadGridLookup_UpdateCommand"   
        onitemcommand="RadGridLookup_ItemCommand"   
        onitemcreated="RadGridLookup_ItemCreated"  > 
        <ClientSettings AllowKeyboardNavigation="true" ClientEvents-OnKeyPress="KeyPressed">  
            <Selecting AllowRowSelect="true" /> 
        </ClientSettings> 
 
        <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" Position="Bottom"></PagerStyle> 
 
        <MasterTableView allowmulticolumnsorting="True" pagesize="15" CommandItemDisplay="TopAndBottom" 
                    autogeneratecolumns="False" DataKeyNames="NounID" datasourceid="ObjectDataSourceLookup" > 
          
        <RowIndicatorColumn Visible="False">  
        <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
 
        <ExpandCollapseColumn Visible="False" Resizable="False">  
        <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~\RadControls\Skins\Mac\Grid\Update.gif"   
                        EditImageUrl="~\RadControls\Skins\Mac\Grid\Edit.gif" InsertImageUrl="~\RadControls\Skins\Mac\Grid\AddRecord.gif"   
                        CancelImageUrl="~\RadControls\Skins\Mac\Grid\Cancel.gif"   
                        UniqueName="EditCommandColumn" EditText="Edit Noun">  
                </telerik:GridEditCommandColumn> 
              
                <telerik:GridBoundColumn   DataField="NounId" DataType="System.Int32" HeaderText="ID"   
                    ReadOnly="True" SortExpression="NounId" UniqueName="NounId" Visible="false">  
                </telerik:GridBoundColumn> 
 
                <telerik:GridTemplateColumn HeaderText="Noun" DataField="Noun" SortExpression="Noun" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" UniqueName="NounTemplate">  
                    <ItemTemplate > 
                        <asp:Label ID="lblNoun" runat="server" Text='<%#Eval("Noun")%>' /> 
                    </ItemTemplate> 
                    <EditItemTemplate > 
                        <asp:TextBox ID="txtNoun" Text='<%#Bind("Noun")%>' runat="server" Width="80%" /><asp:RequiredFieldValidator ID="rValNoun" runat="server" ControlToValidate="txtNoun" ErrorMessage="*" Enabled="true" Text="Required Field" /> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                  
                <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this record?" ButtonType="ImageButton" ImageUrl="~\RadControls\Skins\Mac\Grid\Delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">  
                        <HeaderStyle Width="20px" /> 
                </telerik:GridButtonColumn>                  
            </Columns> 
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="true" /> 
        </ClientSettings>          
    </telerik:RadGrid> 
 
</asp:Content> 
 

using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
using System.Collections.Generic;  
using Telerik.Web.UI;  
 
 
namespace MIDI_Internal.Lookups.NSNs  
{  
    public partial class Nouns : MIDI_Internal.AppCode._libraries.LookupBasePage  
    {  
        protected void Page_PreInit(object sender, EventArgs e)  
        {  
            Page.Theme = (string)Session["MyTheme"];  
        }  
 
        protected void Page_Load(object sender, EventArgs e)  
        {  
            RadGridLookup.MasterTableView.EditMode = GridEditMode.InPlace;  
            // wire sort event handler to take care of sorting after an insert occurs (see base class event handler)  
            RadGridLookup.SortCommand += new GridSortCommandEventHandler(RadGridLookup_SortCommand);  
 
        }  
 
        /// <summary> 
        /// handles users selection to change the paging style at the footer of the grid  
        /// </summary> 
        /// <param name="sender"></param> 
        /// <param name="e"></param> 
        protected virtual void ddlPaging_SelectedIndexChanged(object sender, EventArgs e)  
        {  
            // Get current selected Paging Option //  
            //string currentPager = ddlPaging.SelectedValue.ToString();  
            //UpdatePagingThemes(RadGridLookup, currentPager);  
        }  
 
        /// <summary> 
        /// When a noun is inserted in the grid, ascertain there are no duplicate nouns in the tbMIDI_noun table that exist with this noun,   
        /// this event will look for this Noun and cancel the insert if a duplicate exist, display to user.  
        /// Requirements met:   
        ///         4.5.3.1.4 NOUN-1 Noun - no duplicates  
        ///         4.5.3.1.2 NOUN-2 Ability to add a new noun  
        /// </summary> 
        /// <param name="source">RadGrid</param> 
        /// <param name="e"></param> 
        protected void RadGridLookup_InsertCommand(object source, GridCommandEventArgs e)  
        {  
            if ((e.Item is GridDataInsertItem) && (e.Item.OwnerTableView.IsItemInserted))  
            {  
                GridDataInsertItem edititem = (GridDataInsertItem)e.Item;  
                string strVal = ((TextBox)edititem["NounTemplate"].FindControl("txtNoun")).Text;  
 
                AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable _noun = new MIDI_Internal.AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable();  
                _noun = BLL_Noun.GetDT(null);  
 
 
                DataRow[] _dr1 = _noun.Select("Noun='" + strVal.Replace("'", "''").ToString() + "'");  
 
                if (_dr1.Length > 0)  
                {  
                    e.Canceled = true;  
                    DisplayAlertMessage("Can not insert this noun, the noun already exists");  
                }  
                _noun.Dispose();  
                _noun = null;  
 
            }  
        }  
 
        /// <summary> 
        /// When an item is deleted from the noun grid, ascertain there are no NSNs that exist with this noun, user must delete these first.  
        /// this event will look for thise NSNs and cancel the delete if NSNs exist, display to user.  
        /// Requirements met:   
        ///         4.5.3.1.4 NOUN-4  
        ///         4.5.3.1.4 NOUN-4.1  
        /// </summary> 
        /// <param name="source">RadGrid</param> 
        /// <param name="e"></param> 
        protected override void RadGridLookup_DeleteCommand(object source, GridCommandEventArgs e)  
        {  
            base.RadGridLookup_DeleteCommand(source, e);  
            int id = 0;  
            AppCode.DALs.MIDI_DAL.tbMIDI_NSNDataTable _nsn = new MIDI_Internal.AppCode.DALs.MIDI_DAL.tbMIDI_NSNDataTable();  
 
            //data key value not in the GridCommandEventArgs object, need to extract  
            //id = int.Parse(((GridTableCell)(RadGridLookup.MasterTableView.Controls[0] as Table).Rows[e.Item.RowIndex].Cells[3]).Text);  
            id = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["NounID"].ToString());  
 
            //_nsn = BLL_NSN.GetDT(null);  
            _nsn = BLL_NSN.RetrieveNSNByNounForm(-1, id);  
 
            DataRow[] _dr1 = _nsn.Select("nounId=" + id.ToString());  
 
            if (_dr1.Length > 0)  
            {  
                e.Canceled = true;  
                string NSNs = "";  
                for (int i = 0; i < _dr1.Length; i++)  
                {  
                    NSNs += @"\n";  
                    NSNs += "" + _dr1[i]["NSN"].ToString() + "";  
                }  
                DisplayAlertMessage("Can not delete this noun, NSN records exist: " + NSNs);  
            }  
 
            _nsn.Dispose();  
            _nsn = null;  
        }  
 
        /// <summary> 
        /// When a noun is updated in the grid, ascertain there are no nouns that match the updated value in the tbMIDI_Noun table,  
        /// can not add duplicates  
        /// this event will look for this noun in tbMIDI_Noun and cancel the update if it exist, display to user.  
        /// Requirements met:  
        ///         4.5.3.1.4 NOUN-3  Ability to select and modify an existing noun  
        /// </summary> 
        /// <param name="source">RadGrid</param> 
        /// <param name="e"></param> 
        protected override void RadGridLookup_UpdateCommand(object source, GridCommandEventArgs e)  
        {  
 
            //Get the GridEditableItem of the RadGrid          
            GridEditableItem eeditedItem = e.Item as GridEditableItem;  
            //Get the primary key value using the DataKeyValue.          
            string NounID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["NounID"].ToString();  
            //Access the textbox from the edit form template and store the values in string variables.          
            string strVal = (editedItem["NounTemplate"].FindControl("txtNoun") as TextBox).Text;  
 
            AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable _noun = new MIDI_Internal.AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable();  
            _noun = BLL_Noun.GetDT(null);  
 
            DataRow[] _dr1 = _noun.Select("Noun='" + strVal.Replace("'", "''").ToString() + "'");  
 
            if (_dr1.Length > 0 && (string.Compare(strVal, (string)Session["savedOldValue"], StringComparison.CurrentCultureIgnoreCase) != 0))  
            {  
                e.Canceled = true;  
                DisplayAlertMessage("Can not update this noun, the noun name already exists in the database.");  
                (editedItem["NounTemplate"].FindControl("txtNoun") as TextBox).Text = (string)Session["savedOldValue"];  
            }  
            _noun.Dispose();  
            _noun = null;  
 
        }  
 
        protected override void RadGridLookup_ItemCreated(object sender, GridItemEventArgs e)  
        {  
            base.RadGridLookup_ItemCreated(sender, e);  
            if (e.Item is GridFilteringItem)  
            {  
                AdjustFilterColumnTextBox("NounTemplate", 80, e);  
            }  
        }  
 
 
    }  
}  
 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Sep 2008, 09:53 AM
Hi Gary,

  • Try setting AllowAutomaticInserts and AllowAutomaticUpdates property to  false and see if the events are getting fired properly.
  • This error may occur when you have added a control from RadControls for ASP.NET AJAX to a page which does not contain a ScriptManager control. To resolve that error please add a ScriptManager control to your page :       
<asp:ScriptManager ID="ScriptManager1" runat="server"
        </asp:ScriptManager> 

  
        If you are using master pages you can add the ScriptManager control       there. The ScriptManager control must precede all controls from the RadControls for ASP.NET AJAX suite. For further details about the ScriptManager control you can check
http://ajax.asp.net/docs/overview/ScriptManagerOverview.aspx.

Thanks
Shinu
0
Gary
Top achievements
Rank 1
answered on 15 Sep 2008, 10:44 AM
Hi Shinu-

The script manager was in place, we did find the problem and was hoping you have a work around.  In the master page Page_Init event, we added a Page.DataBind() call.  When we removed this line, the events fired again.  Any ideas? 

Thanks,
Gary
Tags
Grid
Asked by
Gary
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gary
Top achievements
Rank 1
Share this question
or