Link to home
Start Free TrialLog in
Avatar of AnneSKS

asked on

Save content of a page before opening or closing a radwindow using javascript

I have a Telerik ListView with an upload button that opens a radwindow to upload files.
Once the file is uploaded in the radwindow, the windows is closed using javascript and the gridview is refreshed with the content of the upload.
This is working very well. However I would like to save the gridview either before opening the radwindow or before closing the radwindow and refreshing the gridview.

This is what I have done so far:
Option a: I have added the following event (btnUpload_OnCommand) to the btnUpload in the ListView. This event is calling the Update function to save the data in the gridview. However it is not firing.

Option b: I have tried to add the following code PageMethods.Update in the javascript function that is refreshing the gridview,
to call the Update function in the code behind,  but it does not work,

I am pretty new to javascript, so obviously there is something that I am missing.
Thanks in advance for your help.


ascx control code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="sks_Application.ascx.cs" Inherits="Sapphire.Control.Application.sks_Application" %>

<%@ Register Src="~/Control/Shared/sks_RadioButton.ascx" TagName="btnRadio" TagPrefix="sks" %>

    <tlk:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function ShowEditForm(qs, rowIndex) {
                window.radopen("FileAppUpload.aspx?" + qs, "UserListDialog");
                return false;

            function refreshGrid() {
                //PageMethods.Update; NOT WORKING
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");

            Telerik.Web.UI.RadButton.prototype.get_uniqueGroupName = function () {
                return this.get_groupName();

<tlk:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"/>
<tlk:RadAjaxLoadingPanel runat="server" ID="gridLoadingPanel"/>

<asp:Panel ID="pnlQuestion" runat="server" CssClass="Group" Width="98%">

<tlk:RadListView ID="LV" runat="server"  DataKeyNames="AppID, AnswerID"
    OnNeedDataSource="LV_NeedDataSource" OnItemDataBound="LV_ItemDataBound">

<fieldset style="border: none;" >
    <table cellpadding="0" cellspacing="0"   >
        <td  Class="Top" style="Width:20px; vertical-align:Top; padding-top:10px">
                <asp:Label ID="lblAppID" runat="server" Text='<%# Eval("AppID") %>' Visible="false" /> 
                <asp:Label ID="lblAnswerID" runat="Server" Text='<%# Eval("AnswerID") %>' Visible="false" />
                <asp:Label ID="lblIsFile" runat="Server" Text='<%# Eval("IsFile") %>' Visible="false" />
              <tlk:RadButton ID="btnUpload"  Text="Attach/remove file(s)" runat="server" Skin="Metro" Width="130px"  AutoPostBack="true" Visible="False"  OnCommand="btnUpload_OnCommand"/>                    
              <hrz:Label ID="lblAAnswer" runat="server" Text='<%# Eval("AAnswer") %>'  TextBoxCSS="AnswerLabel"  /> 

    <tlk:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
            <tlk:RadWindow ID="UserListDialog" runat="server" Title="Attach/Remove file(s)" Height="500px"
                Width="520px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"  Modal="true">

Open in new window

ascx.cs code behind:
using System;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Sapphire.Control.Shared;
using Sapphire.App_Class;

namespace Sapphire.Control.Application
    public partial class sks_Application : System.Web.UI.UserControl
        protected void LV_NeedDataSource(object source, Telerik.Web.UI.RadListViewNeedDataSourceEventArgs e)
            DTO.Val v = new DTO.Val();

            DTO.ApplicationList A = new DTO.ApplicationList();
            BLL.Application AL = new BLL.Application();
            v.AssessID = this.AssessID;
            v.AppID = this.AppID;
            v.SectionNo = this.SectionNo;

            A = AL.Select(v);

            this.LV.DataSource = A;

        public void Update()
            this._IsValid = true;
            _ErrorMessage = string.Empty;
            int i = 0;

            DTO.Application a = new DTO.Application();
            BLL.Application AL = new BLL.Application();
            DTO.Val av = new DTO.Val();

                while (i < this.LV.Items.Count)
                    RadListViewDataItem Item = LV.Items[i];

                    a = GetItem(false, Item); //get the data in the selected row
                    if (a.IsEmpty == false | a.IsDirty == true)
                        av = AL.UpdateData(a);
                        if (!string.IsNullOrEmpty(av.ErrMsg))
                            _ErrorMessage = av.ErrMsg;

                    i = i + 1;

                _IsValid = false;
                _ErrorMessage = "An unknown error has occurred.  Please check the values entered & try again.";


        protected void LV_ItemDataBound(object sender, RadListViewItemEventArgs e)
            if (e.Item is RadListViewDataItem)
                int AppID = int.Parse(((Label)e.Item.FindControl("lblAppID")).Text.ToString());
                int AnswerID = int.Parse(((Label)e.Item.FindControl("lblAnswerID")).Text.ToString());
                bool isFile = bool.Parse(((Label)e.Item.FindControl("lblIsFile")).Text.ToString());

                if (isFile==true)
                    btnUpload.Visible = isFile;
                    string qs = "AssessID=" + this.AssessID + "&AppID=" + AppID + "&AnswerID=" + AnswerID; 

                    if (btnUpload != null) 
                        //btnUpload.Attributes["href"] = "javascript:void(0);";
                        btnUpload.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", qs, 1);

        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
            if (e.Argument == "Rebind")

        protected void btnUpload_OnCommand(object sender, EventArgs e) //Is not firing


Open in new window

Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial