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

Get Workbook data after SaveWorkbook is called?

3 Answers 201 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 04 Feb 2018, 08:07 PM

Is there a way to trigger a server side event after the SaveWorkbook is called from the custom provider?

Once the Save button is clicked I need to validate what the user put in the cells and modify the UI based on if the user did not enter the data in the cells correctly. 

Basically I need to get back to the code behind page with the spreadsheet data after the SaveWorkbook method has been called.

Right now I can validate the data in the SaveWorkbook method but I cant do anything with it since I cant get back to the page.

 

Thanks

Brian

3 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 04 Feb 2018, 09:56 PM

I thought of a hacky way to do it by passing the session object to the custom provider and saving the worksheet in it. Is there a way to make the call from the client side to .save() not asynchronous? Right now it returns right away. If it waited until the SaveWorkbook method finished I could just post back and check the session variable for my results.

var spread = $find("<%= RadSpreadsheet1.ClientID %>");
spread.save();  <<<--- returns right away.

Thanks

Brian

 

0
Brian
Top achievements
Rank 1
answered on 05 Feb 2018, 07:56 PM

Actually after messing with it some more it seems the Save method is not asynchronous. A combination of client side button click event call to save and a server side click event on the same button as well seems to work. I populate the Session variable with the workbook in the provider SaveWorkbook method then get it out in the server side button click event. 

Seems to work :)

Here is my play code. Might not be the best method but until I hear otherwise this works.

The save button on the form:
<telerik:RadButton runat="server" ID="btnSave" AutoPostBack="true" OnClientClicked="SaveWorkbookButtonClick" OnClick="btnSave_Click" Text="Save" Visible="false"></telerik:RadButton>


Javascript SaveWorkbookButtonClick() method to call the custom provider SaveWorkbook method:
     <script type="text/javascript">     
         function SaveWorkbookButtonClick() {
             var spread = $find("<%= RadSpreadsheet1.ClientID %>");
             spread.save();
         }
    </script>


Provider constructor adds the session object
HttpContext session;

public SpreadsheetProvider1(HttpContext session) : base()
        {
            this.session = session;
        }

The providers SaveWorkbook method to put the workbook into the session:
  public override void SaveWorkbook(Workbook workbook)
        {
            session.Session.Add("workbook", workbook);
        }


Server side button save method to get the workbook from the session:
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Workbook workbook = (Workbook)Session["workbook"];
        }

 

Brian

 

0
Peter Milchev
Telerik team
answered on 07 Feb 2018, 05:13 PM
Hello Brian,

I would also recommend checking the approach suggested in the Access the Spreadsheet workbook on the server KB article if is more suitable for your scenario: Parse the Request.Params["__CALLBACKPARAM"] property value by using the .FromJson() method of the static Telerik.Web.Spreadsheet.Workbook class 

protected void Page_Load(object sender, EventArgs e)
{
    if (IsCallback && Request.Params["__CALLBACKID"] == RadSpreadsheet1.UniqueID)
    {
        Workbook workbook = Telerik.Web.Spreadsheet.Workbook.FromJson(Request.Params["__CALLBACKPARAM"]);
    }
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If IsCallback AndAlso Request.Params("__CALLBACKID") = RadSpreadsheet1.UniqueID Then
        Dim workbook As Workbook = Telerik.Web.Spreadsheet.Workbook.FromJson(Request.Params("__CALLBACKPARAM"))
    End If
End Sub


Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Spreadsheet
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or