Window does not show after grid item command

2 posts, 0 answers
  1. Egbert
    Egbert avatar
    21 posts
    Member since:
    Dec 2010

    Posted 07 May 2014 Link to this post

    Hi,

    I'm using a RadGrid with a delete button.
    When clicking the delete button, I like to show a window confirm box.
    The box will not be shown when the grid in the AjaxUpdatedControl list.

    How can I show the window and keep the RadGrid in the AjaxUpdatedControl list?

    Thanks,
    Egbert

    Here is the xaml and code file:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ReportsGeneral.ascx.cs"
        Inherits="ReportsGeneral" %>
     
    <%@ Register TagPrefix="uc" TagName="InfoPanel" Src="~/InfoPanel.ascx" %>
    <%@ Register TagPrefix="uc" TagName="RisWindow" Src="~/RisWindow.ascx" %>
     
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function OnClientFilesUploaded(sender, args) {
                $find('<%=RadAjaxManager1.ClientID %>').ajaxRequest();
            }
        </script>
    </telerik:RadScriptBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="false">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadAsyncUploadReport" />
                    <telerik:AjaxUpdatedControl ControlID="RadGridReports" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div style="margin: 15px;">
        <center>
            <table>
                <tr>
                    <td valign="top">
                        Begin
                        <telerik:RadCalendar ID="RadCalendar1" runat="server">
                        </telerik:RadCalendar>
                    </td>
                    <td rowspan="2" valign="top" style="margin-left: 10px; padding-left: 10px;">
                        Rapporten
                        <telerik:RadGrid ID="RadGridReports" runat="server" AllowPaging="True" ActiveItemStyle-Wrap="True"
                            ShowStatusBar="true" AllowSorting="True" AllowMultiRowEdit="true" AutoGenerateColumns="false"
                            AllowAutomaticInserts="true" OnNeedDataSource="RadGridReports_NeedDataSource" ClientSettings-Selecting-AllowRowSelect="true" ClientSettings-EnablePostBackOnRowClick="true"
                            OnItemCommand="RadGridReports_ItemCommand">
                            <MasterTableView PageSize="10" NoMasterRecordsText="No data">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="report_id" HeaderText="ID" UniqueName="id" Display="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="owner" HeaderText="Eigenaar" UniqueName="owner">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="filename" HeaderText="Rapport" UniqueName="filename">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="info" HeaderText="Info" UniqueName="info" Display="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridButtonColumn UniqueName="DeleteReportCommand" CommandName="DeleteReport"
                                        ButtonType="ImageButton" ImageUrl="~/Skins/Office2010Blue/Grid/Delete.png" Text="Verwijder"
                                        ItemStyle-Width="24px">
                                    </telerik:GridButtonColumn>
                                </Columns>
                            </MasterTableView>
                            <ClientSettings EnableRowHoverStyle="true">
                            </ClientSettings>
                        </telerik:RadGrid>
                        <br />
                        <telerik:RadButton runat="server" ID="checkBoxOnlyShowMyReports" Text=" Alleen eigen rapporten tonen"
                        ButtonType="ToggleButton" ToggleType="CheckBox" OnClick="checkBoxOnlyShowMyReports_Click"> </telerik:RadButton>
                        <br />
                        <br />
                        <asp:Panel runat="server" GroupingText="Upload rapport">
                            <telerik:RadAsyncUpload ID="RadAsyncUploadReport" runat="server" OnFileUploaded="RadAsyncUploadReport_FileUploaded"
                                OnClientFilesUploaded="OnClientFilesUploaded" AllowedFileExtensions="xlsx" Localization-Select="Selecteer" Width="99%">
                            </telerik:RadAsyncUpload>
                            <br />
                        <uc:InfoPanel ID="InfoPanel1" runat="server" Type="note" Text="Je kan alleen rapporten uploaden met de .xlsx extensie!" HeaderText="Let op!"/>
                        </asp:Panel>
                        <br />
                        <div style="text-align: center">
                        <telerik:RadButton ID="buttonGenerateReport" runat="server" Text="Genereer rapport!" OnClick="buttonGenerateReport_Click" Skin="MetroTouch"></telerik:RadButton>
                        </div>
                        <uc:InfoPanel ID="InfoPanel2" runat="server" Type="note" Text="Bezig met invullen van het rapport!" HeaderText="" Visible="false"/>
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        Eind
                        <telerik:RadCalendar ID="RadCalendar2" runat="server">
                        </telerik:RadCalendar>
                    </td>
                    <td>
                          
                    </td>
                </tr>
            </table>
            <uc:RisWindow runat="server" ID="windowWarning" />
            <telerik:RadNotification ID="RadNotification" runat="server" Text="Initial text" Position="Center" AutoCloseDelay="0" Width="350" Title="Current time" EnableRoundedCorners="true" />
            <telerik:RadWindow ID="RadWindowConfirm" VisibleOnPageLoad="false" Title="Waarschuwing"
                runat="server" Modal="true" AutoSize="false" Width="400" Height="200" VisibleTitlebar="true"
                VisibleStatusbar="False" Behaviors="None" Skin="MetroTouch">
                <ContentTemplate>
                    <p style="text-align: center;">
                        <asp:Label runat="server" ID="label1" Text="Rapport verwijderen?"></asp:Label>
                    </p>
                    <p style="padding: 10px; text-align: center;">
                        <telerik:RadButton ID="ButtonDeleteReportYes" Text="Ja" AutoPostBack="true" runat="server"
                            OnClick="ButtonDeleteReportYes_Click" Skin="MetroTouch">
                        </telerik:RadButton>
                        <telerik:RadButton ID="RadDeleteReportNo" Text="Nee" AutoPostBack="true" runat="server"
                            OnClick="ButtonDeleteReportNo_Click" Skin="MetroTouch">
                        </telerik:RadButton>
                    </p>
                </ContentTemplate>
            </telerik:RadWindow>
        </center>
    </div>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.IO;
    using Ris.Classes;
    using System.Data;
    using SpreadsheetLight;
    using DocumentFormat.OpenXml.Spreadsheet;
     
    public partial class ReportsGeneral : System.Web.UI.UserControl
    {
        private DbHours dbHour = new DbHours();
        private DbProjects dbProject = new DbProjects();
        private DbReports dbReports = null;
        private DbTasks dbTask = new DbTasks();
        private DbUsers dbUser = new DbUsers();
        private string userID = string.Empty;
     
        protected void Page_Load(object sender, EventArgs e)
        {
            this.userID = Session["UserID"].ToString();
            dbReports = new DbReports();
     
            if (!IsPostBack)
            {
                if (Session["OnlyUseMyReports"].ToString() == "0")
                {
                    this.checkBoxOnlyShowMyReports.Checked = false;
                }
                else
                {
                    this.checkBoxOnlyShowMyReports.Checked = true;
                }
            }
        }
     
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
        }
     
        protected void UploadReport_Click(object sender, EventArgs e)
        {
            this.RadAsyncUploadReport.Visible = true;
        }
     
        protected void RadAsyncUploadReport_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            string shortName = dbUser.GetUserItem(this.userID, "short_name");
     
            //// Save the file
            string filename = Global.ReportFolder + shortName + "-" + e.File.FileName;
            e.File.SaveAs(filename);
             
            //// Store the fileinfo in the database
            DbReports dbReports = new DbReports();
            if (!dbReports.ReportExist(e.File.FileName, this.userID))
            {
                dbReports.InsertReport(e.File.FileName, this.userID);
            }
     
            this.RadGridReports.Rebind();
        }
     
        protected void RadGridReports_NeedDataSource(object sender, EventArgs e)
        {
            this.DisplayReports();
        }
     
        private void DisplayReports()
        {
            DataSet dSet = new DataSet();
            if (Session["OnlyUseMyReports"].ToString() == "0")
            {
                dSet = dbReports.GetAllReports();
                this.RadGridReports.Columns[4].Display = false;
            }
            else
            {
                dSet = dbReports.GetMyReports(this.userID);
                this.RadGridReports.Columns[4].Display = true;
            }
     
            this.RadGridReports.DataSource = dSet;
        }
     
        protected void buttonGenerateReport_Click(object sender, EventArgs e)
        {
            if (this.RadGridReports.SelectedItems.Count <= 0)
            {
                this.windowWarning.Show("Selecteer eerst een rapport!");
                return;
            }
     
            // now start with the reporting
            string reportID = Session["ReportID"].ToString();
            string ownerID = dbReports.GetReportItem(reportID, "user_id");
            string reportFileName = dbReports.GetReportItem(reportID, "filename");
            string shortNameOwner = dbUser.GetUserItem(ownerID, "short_name");
     
            string completePath = Global.ReportFolder + shortNameOwner + "-" + reportFileName;
     
            if (reportFileName.ToLower().StartsWith("vakantiekaart"))
            {
                ReportsVacation reportsVacation = new ReportsVacation();
                string reportResult = reportsVacation.CreateReport(completePath, reportFileName);
                if (reportResult != string.Empty)
                {
                    this.windowWarning.Show(reportResult);
                    return;
                }
            }
            else
            {
                ReportsStandard reportsStandard = new ReportsStandard();
                string reportResult = reportsStandard.CreateReport(completePath, reportFileName);
            }
     
            try
            {
                this.FileResponse(reportFileName, Global.ReportOutputFolder + reportFileName);
            }
            catch (Exception ex)
            {
                this.windowWarning.Show("Fout bij opslaan rapport: " + Global.ReportOutputFolder + reportFileName + "! Bestaat de folder?");
            }
     
            //this.RadNotification.VisibleOnPageLoad = true;
            //this.InfoPanel2.Visible = true;
            return;
        }
     
        protected void RadGridReports_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RowClick" && e.Item is GridDataItem)
            {
                e.Item.Selected = true;
     
                GridDataItem item = e.Item as GridDataItem;
                Session["ReportID"] = item["id"].Text;
            }
     
            if (e.CommandName == "DeleteReport")
            {
                GridDataItem item = e.Item as GridDataItem;
                Session["DeleteReportID"] = item["id"].Text;
     
                this.RadWindowConfirm.VisibleOnPageLoad = true;
            }
        }
     
        private void FileResponse(string downloadfilename, string filePath)
        {
            System.IO.FileInfo file = new System.IO.FileInfo(filePath); //-- if the file exists
            if (file.Exists) //set appropriate headers 
            {
                BinaryReader fs = new BinaryReader(file.OpenRead());
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadfilename);
                HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                byte[] bite = fs.ReadBytes((int)file.Length);
                fs.Close();
                HttpContext.Current.Response.BinaryWrite(bite);
            }
        }
         
        protected void checkBoxOnlyShowMyReports_Click(object sender, EventArgs e)
        {
            Session["OnlyUseMyReports"] = "0";
            if (checkBoxOnlyShowMyReports.Checked == true)
            {
                Session["OnlyUseMyReports"] = "1";
            }
     
            this.RadGridReports.Rebind();
        }
     
        protected void ButtonDeleteReportYes_Click(object sender, EventArgs e)
        {
            this.RadWindowConfirm.VisibleOnPageLoad = false;
     
            this.dbReports.DeleteReport(Session["DeleteReportID"].ToString());
        }
     
        protected void ButtonDeleteReportNo_Click(object sender, EventArgs e)
        {
            this.RadWindowConfirm.VisibleOnPageLoad = false;
        }
    }

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 07 May 2014 Link to this post

    Hi Egbert,

    This is a generic AJAX issues - controls that are not part of the partial postback (the RadWIndow in this case) do not get their properties updated on the client. I advise that you examine this sticky thread on opening a RadWindow from the server without depending on AJAX: http://www.telerik.com/forums/opening-radwindow-from-the-server.

    On using a confirm from the server code, I advise you examine this article that explains the scenario's peculiarities and offers examples: http://www.telerik.com/help/aspnet-ajax/window-using-radconfirm-in-server-code.html.


    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top