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

Update Command Does Not Fire

11 Answers 340 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 19 Mar 2011, 12:14 AM

I have implemented many RadGrids and they all work fine but for the life of me I can't understand why the "Update" command doesn't fire when I hit the update button. Here is my code:

Markup: This page is NOT ajaxified

<telerik:RadGrid ID="RadGridEmployees" runat="server" Visible="False" 
    AutoGenerateColumns="False" GridLines="None" AllowSorting="True" 
        AllowPaging="True" Width="975px" AllowAutomaticUpdates="false"
        AllowAutomaticInserts="false" AllowAutomaticDeletes="false">
    <HeaderContextMenu>
    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
    </HeaderContextMenu>
    <PagerStyle Mode="NextPrevNumericAndAdvanced" />
    <MasterTableView AllowPaging="true" PageSize="25" DataKeyNames="UserID" EditMode="InPlace" 
    AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false">
    <Columns
        <telerik:GridEditCommandColumn ButtonType="ImageButton" >
            <ItemStyle VerticalAlign="Top" Width="5px" />
        </telerik:GridEditCommandColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="UserID" 
            Groupable="False" HeaderText="User ID" ReadOnly="True" SortExpression="UserID" 
            UniqueName="UserID">
            <ItemStyle Width="75" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="DIV_NUM" 
            Groupable="False" HeaderText="Division" ReadOnly="True" SortExpression="DIV_NUM" 
            UniqueName="DIV_NUM">
            <ItemStyle Width="50" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="TIN_NUM" 
            Groupable="False" HeaderText="TIN" ReadOnly="True" 
            SortExpression="TIN_NUM" UniqueName="TIN_NUM">
            <ItemStyle Width="100" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="FIRST_NAME" 
            Groupable="False" HeaderText="First Name" ReadOnly="True" 
            SortExpression="FIRST_NAME" UniqueName="FIRST_NAME">
            <ItemStyle Width="75" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" Groupable="False" 
            HeaderText="Last Name" ReadOnly="True" SortExpression="LAST_NAME" 
            UniqueName="LAST_NAME" DataField="LAST_NAME">
            <ItemStyle Width="75" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="BIRTH_YYYYMMDD" 
            DataFormatString="{0:d}" Groupable="False" HeaderText="DOB" ReadOnly="True" 
            SortExpression="BIRTH_YYYYMMDD" UniqueName="BIRTH_YYYYMMDD">
            <ItemStyle Width="75" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="UserEmail" 
            Groupable="False" HeaderText="E-Mail" SortExpression="UserEmail" 
            UniqueName="UserEmail">
            <ItemStyle Width="175" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="secQuestion" 
            Groupable="False" HeaderText="Security Question" ReadOnly="True" 
            SortExpression="secQuestion" UniqueName="secQuestion">
            <ItemStyle Width="125" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="secQuestionAnswer" 
            Groupable="False" HeaderText="Security Question Answer" ReadOnly="True" 
            SortExpression="secQuestionAnswer" UniqueName="secQuestionAnswer">
            <ItemStyle Width="125" />
        </telerik:GridBoundColumn>
        <telerik:GridButtonColumn ButtonType="LinkButton" UniqueName="ResetPasswordColumn" Text="Reset Password" CommandName="Reset">            
            <ItemStyle Width="50px" /> 
        </telerik:GridButtonColumn>
        <telerik:GridTemplateColumn UniqueName="Login">
            <ItemTemplate>
                <a href='Login.aspx?uid=<%# Container.DataItem("UserID") %>'
                                title="Log in as user" target="_blank">Login</a>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>    
                      
    <EditFormSettings CaptionDataField="UserId" EditFormType="Template"
        CaptionFormatString="Edit e-mail address for user: {0}.">
        <EditColumn UniqueName="EditCommandColumn1">
        </EditColumn>
        <FormTemplate>
  
            <div style="padding-top:10px"></div>
                      
            <table width="100%" align="center" cellspacing="5">
                <tr valign="top">
                    <td style="width:20%; font-weight:bold" align="right" nowrap>
                        *Email Address:
                    </td>
                    <td style="width:80%;" align="left">
                        <telerik:RadTextBox ID="RadTextBoxEmail" runat="server" MaxLength="50" SelectionOnFocus="SelectAll"></telerik:RadTextBox>
                        <asp:RequiredFieldValidator ID="ValidatorEmail" runat="server" ErrorMessage="Please enter the e-mail address"
                        Display="None" ControlToValidate="RadTextBoxEmail" Text="*" SetFocusOnError="true" />
                        <ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutEmail"
                        TargetControlID="ValidatorEmail" HighlightCssClass="validatorCalloutHighlight" />
                    </td>
                </tr>
            </table>                      
                      
            <table style="width: 100%">
                <tr>
                    <td align="center" colspan="2">
                        <asp:Button ID="Button1" Text="Update" runat="server" CommandName="Update">
                        </asp:Button
                        <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                        </asp:Button>
                    </td>
                </tr>
            </table>
                      
            <div style="padding-bottom:30px"></div>
                   
        </FormTemplate>
  
    </EditFormSettings>
                  
</MasterTableView>
  
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
</ClientSettings>
  
<FilterMenu>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>

Code (which never fires):

Private Sub RadGridEmployees_UpdateCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Handles RadGridEmployees.UpdateCommand
    Dim lDataItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
    Dim lRadTextBoxEmail As RadTextBox = lDataItem.FindControl("RadTextBoxEmail")
    Dim lUserId As String = lDataItem.GetDataKeyValue("UserID")
    UserServiceHelper.UpdateUserEmail(lUserId, lRadTextBoxEmail.Text.Trim.ToLower)
    RadGridEmployees.EditIndexes.Clear()
End Sub


I don't get it...anyone?

11 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Mar 2011, 10:08 PM
Hello Jfkrueger,

A possible reason for this to happen is that you are invoking RadGrid.Rebind on each and every postback. Could you please post the rest of your code so that we can examine it?

Regards,
Daniel
the Telerik team
0
jfkrueger
Top achievements
Rank 1
answered on 20 Mar 2011, 03:23 PM
Hello,

Thanks for the response but that is not it. I am aware that could cause the issue but I am using the NeedDataSource event of the grid and only rebinding when necessary. The NeedDataSource does not get called upon clicking the update button. Here is the rest of my code:

#Region "Global Variables"
Private _groupNumber As String 
Private _divisionNumber As String 
#End Region
#Region "Protected Methods"
''' <summary>
''' Page Load event handler.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' Adds event handlers for the group and division drop-down controls, 
''' sets properties for the group selector control and sets the visibility
''' of the employee grid.
''' </remarks>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    AddHandler GroupSelector.OnGroupChanged, AddressOf GroupChanged
    AddHandler DivisionSelector.OnDivisionChanged, AddressOf DivisionChanged
    GroupSelectorControl.IsGroupSelectionRequired = True
    GroupSelectorControl.IncludeUsInList = User.IsInRole("accessUs")
    RadGridEmployees.Visible = RadGridEmployees.MasterTableView.Items.Count > 0
End Sub
#End Region
#Region "Private Methods"
''' <summary>
''' Page Unhandled Exception error handler.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub EmployeeLookup_Error(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Error
    ExceptionPolicy.HandleException(Server.GetLastError, "Global Policy")
End Sub
''' <summary>
''' Event handler when the group selection
''' has changed through the group listing
''' control.
''' </summary>
''' <param name="groupNumber"></param>
''' <remarks></remarks>
Private Sub GroupChanged(ByVal groupNumber As String)
    _groupNumber = groupNumber
    _divisionNumber = "All"
    RadGridEmployees.DataSource = Nothing
    RadGridEmployees.Visible = False
End Sub
''' <summary>
''' Event handler for when the division selection
''' has changed through the division selection 
''' control.
''' </summary>
''' <param name="division"></param>
''' <remarks></remarks>
Private Sub DivisionChanged(ByVal division As String)
    _divisionNumber = division
    RadGridEmployees.DataSource = Nothing
    RadGridEmployees.Rebind()
End Sub
''' <summary>
''' ButtonSubmit click event handler. 
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' Rebinds the employee grid and hides the status panel.
''' </remarks>
Private Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonSubmit.Click
    With RadGridEmployees
        .DataSource = Nothing
        .Rebind()
    End With
    PanelStatus.Visible = False
End Sub
''' <summary>
''' ItemCommand event handler for the employee grid.
''' </summary>
''' <param name="source"></param>
''' <param name="e"></param>
''' <remarks>
''' Handles the Reset command for resetting a password.
''' </remarks>
Private Sub RadGridEmployees_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGridEmployees.ItemCommand
    If String.Compare(e.CommandName, "Reset", True, CultureInfo.CurrentCulture) = 0 Then
        Dim lDataItem As GridDataItem = e.CommandSource.Parent.Parent
        Dim lEmail As String = lDataItem("UserEmail").Text.Trim
        Dim lUserId As String = lDataItem("UserID").Text.Trim
        Try
            AdminHelper.ResetPasswordAndSendEmail(lEmail, lUserId)
            LabelStatus.Text = String.Format(CultureInfo.CurrentCulture, "Successfully updated password and sent an email to the user at {0}.", lEmail)
            LabelStatus.ForeColor = Color.Green
            PanelStatus.Visible = True
        Catch ex As WcfException
            LabelStatus.Text = "There was an error resetting this password and sending an e-mail to the user."
            LabelStatus.ForeColor = Color.Red
            PanelStatus.Visible = True
            ExceptionPolicy.HandleException(ex, "Global Policy")
        End Try
    End If
End Sub
''' <summary>
''' ItemDataBound event handler for the employee grid.    ''' 
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' Various formatting of grid.
''' </remarks>
Private Sub RadGridEmployees_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGridEmployees.ItemDataBound
    If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then
        Dim lDataItem As GridDataItem = e.Item
        Dim lBirthdate As String = lDataItem("BIRTH_YYYYMMDD").Text.Trim
        Dim lEmployeeName As String = String.Format(CultureInfo.CurrentCulture, "{0} {1}", lDataItem("FIRST_NAME").Text.Trim, lDataItem("LAST_NAME").Text.Trim)
        Dim lUsername As String = lDataItem("UserID").Text.Trim 
        If IsDate(lBirthdate) Then
            lBirthdate = CType(lBirthdate, Date).ToShortDateString
            lDataItem("BIRTH_YYYYMMDD").Text = lBirthdate
        End If
        CType(e.Item.Cells(12).Controls(0), LinkButton).Attributes.Add("onclick", _
                String.Format(CultureInfo.CurrentCulture, "return confirm('Are you sure you want to reset the password for {0}?');", lEmployeeName))
        If String.Compare(lUsername, " ", True, CultureInfo.CurrentCulture) <> 0 Then
            Return
        End If
        For Each lControl As Control In e.Item.Cells(2).Controls
            lControl.Visible = False
        Next
        For Each lControl As Control In e.Item.Cells(12).Controls
            lControl.Visible = False
        Next
        For Each lControl As Control In e.Item.Cells(13).Controls
            lControl.Visible = False
        Next
        lDataItem("UserID").Text = "<b><font color='red'>Not On System</font></b>"
    End If
End Sub
''' <summary>
''' NeedDataSource event handler for the employee grid.
''' </summary>
''' <param name="source"></param>
''' <param name="e"></param>
''' <remarks>
''' Fires whenever the employee grid needs a data source and 
''' gets the employee data for the current filter.
''' </remarks>
Private Sub RadGridEmployees_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGridEmployees.NeedDataSource
    If Not Page.IsPostBack Then
        Return 
    End If
    If String.Compare(RadMaskedTextBoxMemberId.Text, String.Empty, False, CultureInfo.CurrentCulture) = 0 _
        And String.Compare(RadTextBoxFirstName.Text, String.Empty, False, CultureInfo.CurrentCulture) = 0 _
        And String.Compare(RadTextBoxLastName.Text, String.Empty, False, CultureInfo.CurrentCulture) = 0 _
        And String.Compare(RadTextBoxUserName.Text, String.Empty, False, CultureInfo.CurrentCulture) = 0 _
        And (String.Compare(_groupNumber, String.Empty, False, CultureInfo.CurrentCulture) = 0 _
             Or String.Compare(_groupNumber, "Select", False, CultureInfo.CurrentCulture) = 0) _
        And (String.Compare(_divisionNumber, String.Empty, False, CultureInfo.CurrentCulture) = 0 _
             Or String.Compare(_divisionNumber, "All", False, CultureInfo.CurrentCulture) = 0) Then
        Return
    End If
    Dim lComboBoxGroups As RadComboBox = GroupSelectorControl.FindControl("RadComboBoxGroupListing")
    Dim lEmployees As DataSet = GroupServiceWrapper.GetEmployeeListing(RadMaskedTextBoxMemberId.TextWithLiterals, _
                                                                               RadTextBoxFirstName.Text.Trim, _
                                                                               RadTextBoxLastName.Text.Trim, _
                                                                               RadTextBoxUserName.Text.Trim, _
                                                                               lComboBoxGroups.SelectedValue, _
                                                                               _divisionNumber)
    With RadGridEmployees
        .DataSource = lEmployees
        .Visible = True
    End With
End Sub
Private Sub RadGridEmployees_UpdateCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Handles RadGridEmployees.UpdateCommand
    Dim lDataItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
    Dim lRadTextBoxEmail As RadTextBox = lDataItem.FindControl("RadTextBoxEmail")
    Dim lUserId As String = lDataItem.GetDataKeyValue("UserID")
    UserServiceHelper.UpdateUserEmail(lUserId, lRadTextBoxEmail.Text.Trim.ToLower)
    RadGridEmployees.EditIndexes.Clear()
End Sub
#End Region

Thanks again!
0
jfkrueger
Top achievements
Rank 1
answered on 21 Mar 2011, 05:08 PM
If I set AutoGenerateColumns="True" and remove my "MasterTableView" node in the grid, the Update command does fire. However this will not work, I need to be able to use my own columns.
0
jfkrueger
Top achievements
Rank 1
answered on 21 Mar 2011, 05:19 PM
I have it reduced down to the following code: This is on an .aspx page, no master pages, no AJAX.

Markup:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="Ebms.Webs.WebForm2" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" Visible="True" 
            AutoGenerateColumns="True" GridLines="None" AllowSorting="True" 
            AllowPaging="True" Width="975px" AutoGenerateEditColumn="False">
  
            <MasterTableView AllowPaging="true" PageSize="25" DataKeyNames="UserID" 
                    EditMode="InPlace" AutoGenerateColumns="false">
                <Columns
                    <telerik:GridEditCommandColumn ButtonType="ImageButton">
                        <ItemStyle VerticalAlign="Top" Width="5px" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn AllowFiltering="False" DataField="UserEmail" 
                        Groupable="False" HeaderText="E-Mail" SortExpression="UserEmail" 
                        UniqueName="UserEmail">
                        <ItemStyle Width="175" />
                    </telerik:GridBoundColumn>
                </Columns>   
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

Code:

Public Class WebForm2
    Inherits System.Web.UI.Page
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
    End Sub
  
    Private Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
  
        Dim lEmployees As DataSet = GroupServiceWrapper.GetEmployeeListing(String.Empty, _
                                String.Empty, _
                                "Smith", _
                                String.Empty, _
                                "0000988", _
                                "All")
  
        With RadGrid1
            .DataSource = lEmployees
            .Visible = True
        End With
  
    End Sub
  
    Private Sub RadGrid1_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
  
    End Sub
  
End Class

Update command still does not fire - this is about as simple as you can get.

Please help! Thanks!
0
jfkrueger
Top achievements
Rank 1
answered on 21 Mar 2011, 05:24 PM
Furthermore...when I actually do click the update button the grid is taken out of update mode and the 1 record that was being returned in this example dissappears - meaning the row is still there but there is no data in it any more. Hitting refresh doesn't help because the "NeedDataSource" event has quit firing altogether. Something is really wrong here.
0
jfkrueger
Top achievements
Rank 1
answered on 21 Mar 2011, 06:27 PM
Thinking my project may have been corrupted in some way I copied the above code into another project and the exact same problem occurs. I'm sure I am just missing something simple but I have no clue what that is.

Thanks!
0
jfkrueger
Top achievements
Rank 1
answered on 21 Mar 2011, 11:58 PM
Found it:

Removing this property in the MasterTableView fixes it: PageSize="25" I'd say there is a bug somewhere. ;-)

Thanks!
0
Zach Tindall
Top achievements
Rank 1
answered on 21 Oct 2011, 02:09 AM
After hours of searching, it turns out that the pagesize setting was the cause to my issue as well.  Telerik, can we get someone to look into this issue?
0
Iana Tsolova
Telerik team
answered on 21 Oct 2011, 08:01 PM
Hi Zach,

Can you elaborate a bit more on your scenario? How is the grid set up, what settings are enabled, what customizations are made? What steps do you perform on it and what happens as a result? Do you see some javascript errors thrown?

All the best,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Zach Tindall
Top achievements
Rank 1
answered on 22 Oct 2011, 02:52 AM
We are using a RadGrid with advanced data binding using the needdatasource event.  For editing, we were using "InPlace"  and letting the grid auto generate the edit controls.  Furthermore we were handling all commands by ourself - Insert, Update, Delete and allowing only one item to be edited or deleted at a time.  We were able to use the insert command and the delete command successfully but the update command would never fire.  Upon hitting "Edit" we were taken into edit mode, but once the update button was triggered the grid would not fire the update command and the item was taken out of edit mode.  I didn't receive any javascript errors which is why this one was so tough to figure out.

Finally, I came across this post and noticed that I had set pagesize in the mastertableview settings.  Once I moved the pagesize setting from the mastertableview settings to the radgrid settings, behavior returned to normal.

If needed, I might have time to prepare a sample project that I can send you.  Just let me know.

Thanks, Zach
0
Iana Tsolova
Telerik team
answered on 25 Oct 2011, 02:05 PM
Hi Zach,

Thank you for sharing your experience and finding with us.

Indeed, it would be great of you if you can isolate the issue in a runnable sample and open a Bug Report. Our developers will look into it and try to fix it shortly.

Greetings,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
Daniel
Telerik team
jfkrueger
Top achievements
Rank 1
Zach Tindall
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or