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

Hi,
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.

Anne

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();
            }
        </script>
    </tlk:RadCodeBlock>


<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">

<ItemTemplate>
<fieldset style="border: none;" >
    <table cellpadding="0" cellspacing="0"   >
    <tr>
        <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" />
        </td>
        <td>
              <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"  /> 
        </td>
    </tr>
    </table>
</fieldset>
</ItemTemplate>
</tlk:RadListView>
</asp:Panel>

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

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();

            try
            {
                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;
                }
                this.LV.Rebind();
            }

            catch
            {
                _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")
            {
                LV.Rebind();
            }
        }

        protected void btnUpload_OnCommand(object sender, EventArgs e) //Is not firing
        {
            Update();
        }

    }
}

Open in new window

AnneSKSAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
See this in the documentation:

add_beforeShow: Adds a function that will be called before RadWindow is shown. You can cancel the closing of RadWindow there by using set_cancel(true) . The name of this function can also be declared in the OnClientBeforeShow property.

add_close: Adds a function that will be called when a RadWindow is closed. The name of this function can also be declared in the OnClientClose property.

and this to get the contents:
get_contentElement: Gets the content element when the RadWindow is used as a controls container (its ContentTemplate ) and not with NavigateUrl .

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.