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

Textbox not updating on focus loss

7 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Geoff
Top achievements
Rank 1
Geoff asked on 18 Jul 2013, 04:45 AM
I have a textbox control in a column template. When in edit mode (Popup), if I change the value of the text box and while leaving focus on the text box, click on update, the old value of the text box is posted back. If I tab out of the text box then click on update, the new value is posted back.
Is there a setting that I am missing, or has anyone else had this problem.
Our Telerik controls are the latest version.

7 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jul 2013, 05:47 AM
Hello,

I have tried but not able to reproduce this issue?

Can you please try with the below code snippet and let me know if any concern.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
       OnNeedDataSource="RadGrid1_NeedDataSource"
       onupdatecommand="RadGrid1_UpdateCommand">
       <MasterTableView DataKeyNames="ID" EditMode="PopUp">
           <Columns>
               <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
               </telerik:GridBoundColumn>
               <telerik:GridTemplateColumn>
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                   </EditItemTemplate>
               </telerik:GridTemplateColumn>
               <telerik:GridEditCommandColumn>
               </telerik:GridEditCommandColumn>
           </Columns>
       </MasterTableView>
   </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data = new[] {
           new { ID = 1, Name = "Name1"},
           new { ID = 2, Name = "Name2"},
           new { ID = 3, Name = "Name3"},
           new { ID = 4, Name = "Name4"},
           new { ID = 5, Name = "Name5"}
       };
 
       RadGrid1.DataSource = data;
   }
 
 
 
   protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem item = e.Item as GridEditableItem;
       TextBox TextBox1 = item.FindControl("TextBox1") as TextBox;
   }




Thanks,
Jayesh Goyani
0
Geoff
Top achievements
Rank 1
answered on 19 Jul 2013, 01:53 AM
Jayesh,
The code you supplied works fine. I found that the problem is that I am using template columns, and unless I load the datasource data  into the template text box in the ItemDatabound event, is does not display in edit mode. When I do this (load the data to the text box), the same code runs before the ItemCommnd code and thus overwrites the data in the textbox that still has focus with the 'pre-edit' data.
How do I avoid this  happening? I need the code to load the data or the text box is blank on edit. 
 Private Sub StagedFiles_ItemDataBound(sender As Objecte As Telerik.Web.UI.GridItemEventArgsHandles StagedFiles.ItemDataBound
 
        Try
 
            'edit mode for grid rows
            If TypeOf e.Item Is Telerik.Web.UI.GridEditableItem Then
 
                If CType(e.ItemTelerik.Web.UI.GridEditableItem).IsInEditMode Then
 
                    'Dim gridRow = CType(e.Item, Telerik.Web.UI.GridEditFormItem)
                    Dim gridRow = CType(e.ItemTelerik.Web.UI.GridEditableItem)
                    Dim data = CType(gridRow.DataItemExodus.WS.Document)
 
                    'Runtime bind the dropdowns
                    Dim combo = CType(gridRow.FindControl("ContainerList"), Telerik.Web.UI.RadComboBox)
                    combo.DataSource = Me.Session("ContainerList")
                    combo.DataBind()
                    If data.ContainerID < 1 Then Integer.TryParse(combo.Items(0).Valuedata.ContainerID)
                    combo.SelectedValue = data.ContainerID.ToString
 
                    combo = CType(gridRow.FindControl("DocTypeList"), Telerik.Web.UI.RadComboBox)
                    combo.DataSource = Me.GetDocTypes(data.ContainerID)
                    combo.DataBind()
                    If data.CategoryDocTypeID < 1 Then Integer.TryParse(combo.Items(0).Valuedata.CategoryDocTypeID)
                    combo.SelectedValue = data.CategoryDocTypeID.ToString
 
                    'set data for text boxes
                    Dim textBox = CType(gridRow.FindControl("NotesText"), Telerik.Web.UI.RadTextBox)
                    textBox.Text = data.UserNotes
 
                    textBox = CType(gridRow.FindControl("UserFilenameText"), Telerik.Web.UI.RadTextBox)
                    textBox.Text = data.UserFilename
 
                End If
 
            End If
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Jul 2013, 09:23 AM
Hello,

I am not able to reproduce issue can you please try with the below code snippet.?

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnUpdateCommand="RadGrid1_UpdateCommand"
        onitemdatabound="RadGrid1_ItemDataBound">
        <MasterTableView DataKeyNames="ID" EditMode="PopUp">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="ContainerList" runat="server" DataTextField="ID" DataValueField="Name">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="DocTypeList" runat="server" DataTextField="ID" DataValueField="Name">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <asp:TextBox ID="NotesText" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <asp:TextBox ID="UserFilenameText" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
           new { ID = 1, Name = "Name1"},
           new { ID = 2, Name = "Name2"},
           new { ID = 3, Name = "Name3"},
           new { ID = 4, Name = "Name4"},
           new { ID = 5, Name = "Name5"}
       };
 
        RadGrid1.DataSource = data;
    }
 
 
 
    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem item = e.Item as GridEditableItem;
 
        RadComboBox ContainerList = item.FindControl("ContainerList") as RadComboBox;
 
        RadComboBox DocTypeList = item.FindControl("DocTypeList") as RadComboBox;
 
        TextBox NotesText = item.FindControl("NotesText") as TextBox;
 
        TextBox UserFilenameText = item.FindControl("UserFilenameText") as TextBox;
    }
 
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode && e.Item is GridEditableItem)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            dynamic data = new[] {
           new { ID = 1, Name = "Name1"},
           new { ID = 2, Name = "Name2"},
           new { ID = 3, Name = "Name3"},
           new { ID = 4, Name = "Name4"},
           new { ID = 5, Name = "Name5"}
       };
 
            RadComboBox ContainerList = item.FindControl("ContainerList") as RadComboBox;
            ContainerList.DataSource = data;
            ContainerList.DataBind();
            ContainerList.SelectedValue = "2";
 
            RadComboBox DocTypeList = item.FindControl("DocTypeList") as RadComboBox;
            DocTypeList.DataSource = data;
            DocTypeList.DataBind();
            DocTypeList.SelectedValue = "3";
 
            TextBox NotesText = item.FindControl("NotesText") as TextBox;
            NotesText.Text = "test1";
 
            TextBox UserFilenameText = item.FindControl("UserFilenameText") as TextBox;
            UserFilenameText.Text = "test2";
        }
    }


Thanks,
Jayesh Goyani
0
Geoff
Top achievements
Rank 1
answered on 21 Jul 2013, 11:09 PM
Jayesh,
The code that I have in the item_databound event will load the template controls with data when in edit mode. If not in edit mode, it will load the grid fields. It is this latter operation that is overwriting the data as the databound event fires prior to the itemCommand event.
If I do not load the grid fields when not in edit mode, no data displays in the grid.
I think that I am missing something basic here, but I cannot figure out what it is.

<telerik:RadGrid ID="StagedFiles" runat="server" AutoGenerateColumns="False" AutoGenerateEditColumn="True" CellSpacing="0" Culture="en-AU" GridLines="Vertical" ShowStatusBar="True">
                    <ExportSettings>
                        <Pdf>
                            <PageHeader>
                                <LeftCell Text="" />
                                <MiddleCell Text="" />
                                <RightCell Text="" />
                            </PageHeader>
                            <PageFooter>
                                <LeftCell Text="" />
                                <MiddleCell Text="" />
                                <RightCell Text="" />
                            </PageFooter>
                        </Pdf>
                    </ExportSettings>
                    <ClientSettings>
                        <Selecting CellSelectionMode="SingleCell" />
                    </ClientSettings>
                    <MasterTableView editmode="PopUp" DataKeyNames="PhysicalFilename">
                        <CommandItemSettings ExportToPdfText="Export to PDF" ShowAddNewRecordButton="False" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True" Created="True">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="OriginalFilename" FilterControlAltText="Filter DirectoryName column" HeaderText="Original Name" ReadOnly="True" UniqueName="OriginalFilename">
                                <ColumnValidationSettings>
                                    <ModelErrorMessage Text="" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Size" DataFormatString="{0:N0}" DataType="System.Int32" FilterControlAltText="Filter Size column" HeaderText="Size" ReadOnly="True" UniqueName="Size">
                                <ColumnValidationSettings>
                                    <ModelErrorMessage Text="" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="UploadDate" DataFormatString="{0:dd/MM/yy HH:mm tt}" DataType="System.DateTime" FilterControlAltText="Filter UploadDate column" HeaderText="Uploaded" ReadOnly="True" UniqueName="UploadDate">
                                <ColumnValidationSettings>
                                    <ModelErrorMessage Text="" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhysicalFilename" FilterControlAltText="Filter FullName column" HeaderText="Physical File" ReadOnly="True" UniqueName="PhysicalFilename" Visible="False">
                                <ColumnValidationSettings>
                                    <ModelErrorMessage Text="" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="DocumentID" DataType="System.Int32" Display="False" FilterControlAltText="Filter DocumentID column" HeaderText="Document ID" ReadOnly="True" UniqueName="DocumentID" Visible="False">
                                <ColumnValidationSettings>
                                    <ModelErrorMessage Text="" />
                                </ColumnValidationSettings>
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="UserFilename" FilterControlAltText="Filter Name column" HeaderText="File Name" UniqueName="UserFilename">
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="UserFilenameText" runat="server">
                                    </telerik:RadTextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="ContainerName" FilterControlAltText="Filter ContainerTemplate column" HeaderText="Container" UniqueName="ContainerTemplate">
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="ContainerList" Runat="server" DataTextField="Name" DataValueField="ContainerID">
                                    </telerik:RadComboBox>
                                </EditItemTemplate>
                                <HeaderTemplate>
                                    Container<br />
                                    <telerik:RadComboBox ID="HeaderContainerList" Runat="server" AutoPostBack="True" DataTextField="Name" DataValueField="ContainerID">
                                    </telerik:RadComboBox>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="ContainerName" runat="server"></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="DocumentTypeDescription" FilterControlAltText="Filter ContainerTemplate column" HeaderText="Doc. Type" UniqueName="DocTypeTemplate">
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="DocTypeList" Runat="server" DataTextField="DocTypeDescription" DataValueField="CategoryDocTypeID">
                                    </telerik:RadComboBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="DocTypeDesc" runat="server"></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn Display="False" FilterControlAltText="Filter Notes column" HeaderText="Notes" UniqueName="Notes">
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="NotesText" Runat="server" Height="70px" MaxLength="500" TextMode="MultiLine" Width="250px">
                                    </telerik:RadTextBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                        <BatchEditingSettings EditType="Cell" />
                        <PagerStyle PageSizeControlType="RadComboBox" />
                    </MasterTableView>
                    <PagerStyle PageSizeControlType="RadComboBox" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>

Private Sub StagedFiles_ItemDataBound(sender As Objecte As Telerik.Web.UI.GridItemEventArgsHandles StagedFiles.ItemDataBound
 
        Try
 
            'edit mode for grid rows
            If TypeOf e.Item Is Telerik.Web.UI.GridEditableItem Then
 
                If CType(e.ItemTelerik.Web.UI.GridEditableItem).IsInEditMode Then
 
                    'Dim gridRow = CType(e.Item, Telerik.Web.UI.GridEditFormItem)
                    Dim gridRow = CType(e.ItemTelerik.Web.UI.GridEditableItem)
                    Dim data = CType(gridRow.DataItemExodus.WS.Document)
 
                    'Runtime bind the dropdowns
                    Dim combo = CType(gridRow.FindControl("ContainerList"), Telerik.Web.UI.RadComboBox)
                    combo.DataSource = Me.Session("ContainerList")
                    combo.DataBind()
                    If data.ContainerID < 1 Then Integer.TryParse(combo.Items(0).Valuedata.ContainerID)
                    combo.SelectedValue = data.ContainerID.ToString
 
                    combo = CType(gridRow.FindControl("DocTypeList"), Telerik.Web.UI.RadComboBox)
                    combo.DataSource = Me.GetDocTypes(data.ContainerID)
                    combo.DataBind()
                    If data.CategoryDocTypeID < 1 Then Integer.TryParse(combo.Items(0).Valuedata.CategoryDocTypeID)
                    combo.SelectedValue = data.CategoryDocTypeID.ToString
 
                    'set data for text boxes
                    Dim textBox = CType(gridRow.FindControl("NotesText"), Telerik.Web.UI.RadTextBox)
                    textBox.Text = data.UserNotes
 
                    textBox = CType(gridRow.FindControl("UserFilenameText"), Telerik.Web.UI.RadTextBox)
                    textBox.Text = data.UserFilename
 
                End If
 
            End If
 
            'Display Mode
            If TypeOf e.Item Is Telerik.Web.UI.GridDataItem AndAlso Not CType(e.ItemTelerik.Web.UI.GridDataItem).IsInEditMode Then
 
                Dim gridRow = CType(e.ItemTelerik.Web.UI.GridDataItem)
                Dim data = CType(gridRow.DataItemExodus.WS.Document)
 
 
                Dim label = CType(gridRow("ContainerTemplate").FindControl("ContainerName"), Label)
 
                label.Text = data.ContainerName
 
                label = CType(gridRow("DocTypeTemplate").FindControl("DocTypeDesc"), Label)
                label.Text = data.DocumentTypeDescription
 
                gridRow("UserFilename").Text = data.UserFilename
                gridRow("Notes").Text = data.UserNotes
 
            End If
 
            'bind data for header dropdowns
            If TypeOf e.Item Is Telerik.Web.UI.GridHeaderItem Then
 
                Dim gridrow = CType(e.ItemTelerik.Web.UI.GridHeaderItem)
 
                Dim combo = CType(gridrow.FindControl("HeaderContainerList"), Telerik.Web.UI.RadComboBox)
                combo.DataSource = Me.Session("ContainerList")
                combo.DataBind()
                combo.SelectedValue = Me.HeaderContainerID
 
            End If
 
        Catch ex As Exception
 
            Dim msg = "Error Binding Items"
            My.Log.WriteEntry(msgTraceEventType.Critical)
            My.Log.WriteException(ex)
 
            Me.ErrList.Add(msg)
            Me.ErrList.Add(ex.Message)
 
        End Try
 
 
    End Sub

Private Sub StagedFiles_UpdateCommand(sender As Objecte As Telerik.Web.UI.GridCommandEventArgsHandles StagedFiles.UpdateCommand
 
        Try
 
            Dim gridRow = CType(e.ItemTelerik.Web.UI.GridEditableItem)
 
            'read the row being edited from the session data - original filename is the key
            Dim originalFilename = CType(gridRow.Item("OriginalFilename").Controls(0), TextBox).Text
 
            Dim data = Me.StagedFilesData
            Dim dataRow = (From r In data Where r.OriginalFilename = originalFilename Select r).FirstOrDefault
            If dataRow Is Nothing Then
 
                Me.ErrList.Add(String.Format("Cannot find {0} in Session Data"originalFilename))
 
            Else
 
                'update data record from the grid
                Dim combo As Telerik.Web.UI.RadComboBox = Nothing
 
                combo = CType(gridRow.FindControl("ContainerList"), Telerik.Web.UI.RadComboBox)
                dataRow.ContainerID = System.Convert.ToInt32(combo.SelectedValue)
                dataRow.ContainerName = combo.SelectedItem.Text
 
                combo = CType(gridRow.FindControl("DocTypeList"), Telerik.Web.UI.RadComboBox)
                dataRow.CategoryDocTypeID = System.Convert.ToInt32(combo.SelectedValue)
                dataRow.DocumentTypeDescription = combo.SelectedItem.Text
 
                Dim textBox = CType(gridRow.FindControl("UserFilenameText"), Telerik.Web.UI.RadTextBox)
                dataRow.UserFilename = textBox.Text
 
                textBox = CType(gridRow.FindControl("NotesText"), Telerik.Web.UI.RadTextBox)
                dataRow.UserNotes = textBox.Text
 
                dataRow.StatusID = 1
                dataRow.UserNotes = String.Empty
 
                'Write back to session
                Me.StagedFilesData = data
 
            End If
 
        Catch ex As Exception
 
            Dim msg = "Error Updateing Item"
            My.Log.WriteEntry(msgTraceEventType.Critical)
            My.Log.WriteException(ex)
 
            Me.ErrList.Add(msg)
            Me.ErrList.Add(ex.Message)
 
        End Try
 
    End Sub

0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Jul 2013, 08:23 AM
Hello,

http://www.telerik.com/community/forums/aspnet-ajax/input/numerictextbox-get-value-is-returning-old-value-onblur.aspx#2250278

OR

<telerik:RadTextBox ID="UserFilenameText" runat="server" onkeyup="onkeyupEvent(this);">
</telerik:RadTextBox>

<script type="text/javascript">
           function onkeyupEvent(obj) {
               $telerik.findControl(document, "UserFilenameText").set_value(obj.value);
           }
          
       </script>


Thanks,
Jayesh Goyani
0
Geoff
Top achievements
Rank 1
answered on 22 Jul 2013, 11:46 PM
Jayesh,
Given that I have a PopOut edit on my RadGrid row, and this contains three controls plus the Update and Cancel buttons, how does the user get the third control to update correctly when clicking the Update button? The only way that they can get the third field to update is to enter the data, click on the previous field (or any prior field) and then the Update button. This does not seem very intuitive and we have never had to deal with this problem with our other control sets. The currently focused field should blur and update the value when I click the Update button, but this does not appear to be happening. As I stated, it could be that I am missing something basic as this is the first project that we have used the Telerik controls on, but I feel that it should be easier than having to implement javascript events.
0
Geoff
Top achievements
Rank 1
answered on 23 Jul 2013, 01:46 AM
Jayesh,
I found that I had another RadGrid in my application that worked as expected without the problems that this thread relates to. I changed the RadGrid definition to match the one that worked and it all started working as expected. The only change I made was to remove the following lines from the RadGrid definition :
                    <ExportSettings>
                        <Pdf>
                            <PageHeader>
                                <LeftCell Text="" />
                                <MiddleCell Text="" />
                                <RightCell Text="" />
                            </PageHeader>
                            <PageFooter>
                                <LeftCell Text="" />
                                <MiddleCell Text="" />
                                <RightCell Text="" />
                            </PageFooter>
                        </Pdf>
                    </ExportSettings>
                    <ClientSettings>
                        <Selecting CellSelectionMode="SingleCell" />
                    </ClientSettings>

and changed to
<ClientSettings EnablePostBackOnRowClick="True">
                                    <Selecting AllowRowSelect="True" />
                                </ClientSettings>
Tags
Grid
Asked by
Geoff
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Geoff
Top achievements
Rank 1
Share this question
or