Get Workbook data after SaveWorkbook is called?

4 posts, 0 answers
  1. Brian
    Brian avatar
    9 posts
    Member since:
    Nov 2011

    Posted 04 Feb 2018 Link to this post

    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

  2. Brian
    Brian avatar
    9 posts
    Member since:
    Nov 2011

    Posted 04 Feb 2018 in reply to Brian Link to this post

    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

     

  3. Brian
    Brian avatar
    9 posts
    Member since:
    Nov 2011

    Posted 05 Feb 2018 in reply to Brian Link to this post

    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

     

  4. Peter Milchev
    Admin
    Peter Milchev avatar
    503 posts

    Posted 07 Feb 2018 Link to this post

    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.
Back to Top