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

RadGrid not updating after Delete Confirmation Dialog

9 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 09 Apr 2020, 07:28 AM

Hello

i just added a Confirmation Dialog to my Radgrid using the radgrid.radconfirm. This works perfectly, but after that the Radgrid is not updated, like it still shows the deleted entry. Refreshing the page obv helps. I already tested the following:

Use advanced binding instead of simple binding.

Change to type BindingList instead of List as Datasourcetype

RadAjaxManager instead of RadAjaxPanel is not possible, because the panel is need as part of the whole concept of the webpage and to ensure that each user is only able to see what he is allowed to see.

Here is the code: ASPX

<%@ Page Title="News - Administration" Language="C#" MasterPageFile="~/AppMaster.master" AutoEventWireup="true" Inherits="News" CodeBehind="News.aspx.cs" %>
 
<%@ Register Src="NewsDetails.ascx" TagName="NewsDetails" TagPrefix="uc" %>
<asp:Content ID="Content" ContentPlaceHolderID="PlaceHolderContent" runat="Server">
  <asp:Label ID="LabelRead" runat="server" Text="<%$Resources:Labels, NoReadRight %>" Visible="false" CssClass="Labels" />
    <asp:Label ID="LabelConfirm" runat="server" Text="<%$Resources:Labels, NoReadRight %>" Visible="false" CssClass="Labels" />
     
    <telerik:RadWindowManager RenderMode="Lightweight" ID="confirmWindow" runat="server" EnableShadow="true">
        </telerik:RadWindowManager>
    <%--RadAjaxPanel--%>
    <telerik:RadAjaxPanel ID="PanelRead" runat="server" LoadingPanelID="RadAjaxLoadingPanel" Visible="false">
        <telerik:RadGrid ID="RadGrid" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowPaging="true" PageSize="20" Width="950px"
            OnItemCommand="RadGrid_ItemCommand" OnInsertCommand="RadGrid_InsertCommand" OnDeleteCommand="RadGrid_DeleteCommand"
            OnUpdateCommand="RadGrid_UpdateCommand">
            <MasterTableView Datasource="ObjectDataSourceNewsEntries" DataKeyNames="NewsEntryID"
                CommandItemDisplay="Top">
                <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="true" AddNewRecordText="Neuer News-Eintrag" />
                <Columns>
                    <%--TimestampString --%>
                    <telerik:GridBoundColumn DataField="TimestampString" HeaderText='<%$Resources:Labels, NewsEntryTimestamp %>'
                        UniqueName="TimestampString" DataFormatString="{0}" DataType="System.String"
                        Display="true" Groupable="false">
                        <HeaderStyle Width="50px" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                        <ItemStyle Wrap="false" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                    </telerik:GridBoundColumn>
                    <%--HeaderText --%>
                    <telerik:GridBoundColumn DataField="HeaderText" HeaderText='<%$Resources:Labels, HeaderText %>'
                        UniqueName="HeaderText" DataFormatString="{0}" DataType="System.String" Display="true"
                        Groupable="false">
                        <HeaderStyle Width="330px" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                        <ItemStyle Wrap="false" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                    </telerik:GridBoundColumn>
                    <%--IsActive --%>
                    <telerik:GridBoundColumn DataField="IsActive" HeaderText='<%$Resources:Labels, IsActive %>'
                        UniqueName="IsActive" DataFormatString="" DataType="System.Boolean" Display="true"
                        Groupable="false">
                        <HeaderStyle Width="50px" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                        <ItemStyle Wrap="false" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                    </telerik:GridBoundColumn>
                    <%--ErstellerUserNameVorname --%>
                    <telerik:GridBoundColumn DataField="ErstellerUserNameVorname" HeaderText='<%$Resources:Labels, ErstellerUserNameVorname %>'
                        UniqueName="ErstellerUserNameVorname" DataFormatString="{0}" DataType="System.String"
                        Display="true" Groupable="false">
                        <HeaderStyle Width="170px" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                        <ItemStyle Wrap="false" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                    </telerik:GridBoundColumn>
                    <%--AenderungsUserNameVorname --%>
                    <telerik:GridBoundColumn DataField="AenderungsUserNameVorname" HeaderText='<%$Resources:Labels, AenderungsUserNameVorname %>'
                        UniqueName="AenderungsUserNameVorname" DataFormatString="{0}" DataType="System.String"
                        Display="true" Groupable="false">
                        <HeaderStyle Width="170px" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                        <ItemStyle Wrap="false" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                    </telerik:GridBoundColumn>
                    <%--Aenderungsdatum --%>
                    <telerik:GridBoundColumn DataField="Aenderungsdatum" HeaderText='<%$Resources:Labels, Aenderungsdatum %>'
                        UniqueName="Aenderungsdatum" DataFormatString="{0}" DataType="System.String"
                        Display="true" Groupable="false">
                        <HeaderStyle Width="80px" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                        <ItemStyle Wrap="false" HorizontalAlign="Left" VerticalAlign="Top" Font-Bold="false" />
                    </telerik:GridBoundColumn>
                    <%--LinkButtonEditCommand--%>
                    <telerik:GridTemplateColumn UniqueName="ColumnEditCommand">
                        <HeaderStyle Width="25px" />
                        <ItemStyle HorizontalAlign="Center" />
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButtonEditCommand" runat="server" CommandName="Edit" ToolTip="<%$Resources:Labels, Edit %>">
                                <asp:Image ID="ImageEditCommand" runat="server" ImageUrl="~/App_Themes/Controlling/EditIcon.gif" />
                            </asp:LinkButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <%--LinkButtonDeleteCommand--%>
                    <telerik:GridTemplateColumn UniqueName="ColumnDeleteCommand">
                        <HeaderStyle Width="25px" />
                        <ItemStyle HorizontalAlign="Center" />
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButtonDeleteCommand" runat="server" CommandName="Delete"
                                ToolTip="<%$Resources:Labels, DeleteToolTip %>">
                                <asp:Image ID="ImageDeleteCommand" runat="server" ImageUrl="~/App_Themes/Controlling/DeleteIcon.png" />
                            </asp:LinkButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <NestedViewTemplate>
                    <uc:NewsDetails ID="NewsDetails" runat="server" />
                </NestedViewTemplate>
                <EditFormSettings UserControlName="NewsCreateUpdate.ascx" EditFormType="WebUserControl">
                    <EditColumn UniqueName="NewsCreateUpdateColumn"></EditColumn>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>
    <%--DataSources--%>
    <asp:ObjectDataSource ID="ObjectDataSourceNewsEntries" runat="server" SelectMethod="GetNewsEntries" TypeName="PortalDataServiceWrapper" />
</asp:Content>

 

C#

using System;
using System.Web.Services;
using Telekom.Platon.PortalModel;
using Telekom.Platon.Web.Code.Base;
using Telekom.PORTAL.Web;
using Telerik.Web.UI;
 
 
public partial class News : AppBasePage
{
    protected override ModulEnum ModulId => ModulEnum.AdminNews;
    protected static Guid GridID = Guid.Empty;
    protected static News n;
    protected static RadGrid RGrid;
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
        PanelRead.Visible = MayRead;
        LabelRead.Visible = !MayRead;
 
        RadScriptManager.RegisterClientScriptInclude(Page.Master, Page.Master.GetType(), "ConfirmRadWindow", ResolveClientUrl("~/Scripts/app/ConfirmRadWindow.js"));
 
 
        if (!Page.IsPostBack)
            DataBind();
    }
 
    protected void RadGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == Telerik.Web.UI.RadGrid.ExpandCollapseCommandName)
        {
            //
            // Expand
            //
            GridDataItem gridDataItem = e.Item as GridDataItem;
 
            string newsEntryIDString = gridDataItem.GetDataKeyValue("NewsEntryID").ToString();
            Guid newsEntryID = new Guid(newsEntryIDString);
 
            NewsEntry dataItem = PortalDataService.GetNewsEntry(newsEntryID);
 
 
            if (!e.Item.Expanded)
            {
                NewsDetails control = (NewsDetails)gridDataItem.ChildItem.FindControl("NewsDetails");
 
                if (control != null &&
                        dataItem != null)
                {
                    control.State.FormattedContent = dataItem.FormattedContent;
                    control.DataBind();
                }
            }
        }
    }
 
    protected void RadGrid_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        NewsCreateUpdate userControl = (NewsCreateUpdate)editedItem.FindControl(GridEditFormItem.EditFormUserControlID);
 
        if (userControl.Timestamp.HasValue) Create(userControl.Timestamp.Value, userControl.HeaderText, userControl.IsActive, userControl.FormattedContent);
    }
 
    protected void RadGrid_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        NewsCreateUpdate userControl = (NewsCreateUpdate)editedItem.FindControl(GridEditFormItem.EditFormUserControlID);
        Guid newsEntryID = GridUtil.GetValue<Guid>("NewsEntryID", e);
 
        if (userControl.Timestamp.HasValue) Update(newsEntryID, userControl.Timestamp.Value, userControl.HeaderText, userControl.IsActive, userControl.FormattedContent);
    }
 
    protected void RadGrid_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        GridID = GridUtil.GetValue<Guid>("NewsEntryID", e);
        RGrid = this.RadGrid;
        n = this;
 
        if (Page.IsValid)
        {
            confirmWindow.RadConfirm("Sind Sie sicher das diese News gelöscht werden soll?", "confirmCallBackFn", 330, 180, null, "Newsmeldung löschen?");
        }
 
    }
 
    private void Create(DateTime timestamp, string headerText, bool isActive, string formattedContent)
    {
        if (Page.IsValid)
        {
            string userID = SecurityService.GetUserID();
 
            NewsEntry newsEntry = NewsEntry.Create(timestamp, headerText, isActive, userID);
 
            if (newsEntry != null)
            {
                newsEntry.FormattedContent = formattedContent;
 
                string message = string.Empty;
                PortalDataService.CreateNewsEntry(newsEntry, out message);
 
                RadGrid.DataBind();
                RadGrid.CurrentPageIndex = 0;
            }
        }
    }
 
    private void Update(Guid newsEntryID, DateTime timestamp, string headerText, bool isActive, string formattedContent)
    {
        if (Page.IsValid)
        {
            string userID = SecurityService.GetUserID();
            NewsEntry newsEntry = PortalDataService.GetNewsEntry(newsEntryID);
 
            if (newsEntry != null)
            {
                newsEntry.Timestamp = timestamp;
                newsEntry.HeaderText = headerText;
                newsEntry.FormattedContent = formattedContent;
                newsEntry.IsActive = isActive;
                newsEntry.Aenderungsdatum = DateTime.Now;
                newsEntry.AenderungsUserID = userID;
 
                PortalDataService.UpdateNewsEntry(newsEntry);
 
                RadGrid.DataBind();
            }
        }
    }
 
    [WebMethod]
    public static void Delete(bool? UserReponse)
    {
        if (GridID != Guid.Empty && UserReponse.Equals(true))
        {
            PortalDataService.DeleteNewsEntry(GridID);
            RGrid.DataBind();
 
 
 
        }
    }
}

 

Any Ideas what i can do?

Regards Michael

9 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 09 Apr 2020, 07:29 AM
I forgot to mention, that the page worked as intended before adding the confirmation dialog.
0
Attila Antal
Telerik team
answered on 13 Apr 2020, 11:16 AM

Hi Michael,

RadGrid is an extended version of the ASP GridView and it comes with its own Data Binding technique which is the Programmatic Data Binding Using the NeedDataSource Event.

The behavior you are seeing is due to the DataBind() method. I highly recommend switching the data binding to use NeedDataSource event and in the Update method, call rebind the Grid RadGrid1.Rebind(). 

You can also check out the How to bind RadGrid properly on server-side article for more information on this.

Kind regards,
Attila Antal
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Michael
Top achievements
Rank 1
answered on 14 Apr 2020, 12:37 PM

Thanks for you reply, Attila.

 

I added a "onneeddatasource" event, deleted the old datasource from the header and the asp page and changed the databind in the update and create script to rebind. But it didnt solved the problem. It seems like the rebind does not fire the "needdatasource" event. Maybe i am missing a setting in the header on the radgrid?

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowPaging="true" PageSize="20" Width="950px"  OnNeedDataSource="RadGrid_NeedDataSource"
            OnItemCommand="RadGrid_ItemCommand" OnInsertCommand="RadGrid_InsertCommand" OnDeleteCommand="RadGrid_DeleteCommand"
            OnUpdateCommand="RadGrid_UpdateCommand">
            <MasterTableView DataKeyNames="NewsEntryID" EnableViewState="false"
                CommandItemDisplay="Top"

0
Attila Antal
Telerik team
answered on 17 Apr 2020, 08:19 AM

Hi Michael,

You will need to ensure that RadGrid only binds data using the NeedDataSource event not calling DataBind() method anywhere in the code.

Here is a complete example:

<telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource"></telerik:RadGrid>

protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = Enumerable.Range(1, 4).Select(x => new { ID = x, Description = "Description " + x });
}

In addition to binding data, you may also consider opening the Developer Tools of the browser and monitor the console tab for potential JavaScript errors. You can check out the Debug JavaScript section of the following Blog Post for tips: Improve Your Debugging Skills with Chrome DevTools

All JavaScript errors must be eliminated as they tend to break the Grid's embedded logic. 

JavaScript errors can also be generated if AJAX is enabled while there is a server-side error. Try disabling AJAX temporarily and test the application without that, see Get more descriptive errors by disabling AJAX.

My advice is to ensure that the application works and only then turn AJAX on.

I hope these steps will help resolve the issue.

Kind regards,
Attila Antal
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Michael
Top achievements
Rank 1
answered on 17 Apr 2020, 11:52 AM

Hello Attila

I checked for Java Script Errors and there are none. While i was searching for Databindd() calls, i saw that i use a nestedview in that grid and it overrides the normal databind. Maybe this causes the error and i have to handle this differently? Here is the code for the nested view which uses an editor for updating or creating new items:

 

using System;
using System.Diagnostics;
using Telekom.Platon.Web.Code.Base;
 
public partial class NewsDetails : StatefulControlBase<NewsDetails.Model>
{
    [DebuggerDisplay("{FormattedContent}")]
    [Serializable]
    public class Model
    {
        public string FormattedContent;
 
 
 
        public override string ToString()
        {
            return FormattedContent?.Length > 0
                ? FormattedContent.Length > 30
                    ? FormattedContent.Substring(0, 26) + " ..."
                    : FormattedContent
                : null;
        }
    }
 
 
 
    public override void DataBind()
    {
        RadEditor.Content = State.FormattedContent;
    }
}

 

<%@ Control Language="C#" AutoEventWireup="true" Inherits="NewsDetails" Codebehind="NewsDetails.ascx.cs" %>
<table>
    <colgroup>
        <col width="25px" />
        <col width="*" />
    </colgroup>
    <tr>
        <td>
        </td>
        <td>
            <telerik:RadEditor ID="RadEditor" runat="server" Language="de-DE" Width="350px" Enabled="false"/>
        </td>
    </tr>
</table>

 

 

0
Attila Antal
Telerik team
answered on 20 Apr 2020, 04:15 PM

Hi Michael,

It is likely the override is breaking the application as the Grid itself calls that at some point. In order to tell you that, I will need to be able to debug the application. Therefore, It would be helpful if you could share a runnable sample or at least describe the steps that would help me replicate the issue locally.

You can try isolating the issue by removing unrelated controls, methods, events one by one.

Kind regards,
Attila Antal
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Michael
Top achievements
Rank 1
answered on 23 Apr 2020, 06:39 PM

Hello Attila,

thanks for your reply. Meanwhile i just commented the Nested View out, but that does not change any bahaviour of the grid, so my conclusion for the nested view part, it cant be the problem.

While debugging more, i found Java Script Errors (sorry for not finding them earlier) but i have no clue what do to against them, as they look "strange" to me.

Here is one of the errors and i attached the file which can be found following the link

Es wurde eine Ausnahme ausgelöst: in Zeile 1578, Spalte 7237 in http://localhost:2250/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManagerApp_TSM&compress=1&_TSM_CombinedScripts_=;;System.Web.Extensions,+Version=4.0.0.0,+Culture=neutral,+PublicKeyToken=31bf3856ad364e35:de-DE:9ead301a-2c07-4fc5-be19-f8423a34e117:ea597d4b:b25378d2;Telerik.Web.UI:de-DE:bb184598-9004-47ca-9e82-5def416be84b:16e4e7cd:f7645509:4877f69a:b2e06756:24ee1bba:92fe8ea0:fa31b949:c128760b:874f8ea2:33715776:19620875:f46195d3:490a9d4e:ed16cbdc:88144a7a:bd8f85e4:58366029

 

 

 

 

 

 

 

 

 

0
Michael
Top achievements
Rank 1
answered on 23 Apr 2020, 06:58 PM
I attached the link file of the Java Script Error. Just delete the .jpg ending as it is a normal txt file.
0
Peter Milchev
Telerik team
answered on 28 Apr 2020, 12:42 PM

Hello Michael,

Please check and share the whole stack trace of the error as it might provide more information on the issue. 

It seems that there is an error with the MS AJAX framework itself:

You can click on the links and sources of the JavaScript error in the browser's console and get more information on exactly where the issue appears.

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Attila Antal
Telerik team
Peter Milchev
Telerik team
Share this question
or