EditForm / UserControl - attempting to fire "Update" command from Javascript

1 posts, 0 answers
  1. Simon
    Simon avatar
    1 posts
    Member since:
    Dec 2017

    Posted 15 Dec 2017 Link to this post

    Here is what is working:
    I have a RadGrid with a single MasterTableView, loading data from a database table.
    Users are able to edit the data using a WebUserControl:
                    <EditFormSettings UserControlName="JIBCoding.ascx" EditFormType="WebUserControl" PopUpSettings-Height="600" PopUpSettings-Width="1000">
                        <EditColumn UniqueName="order_by">
                        </EditColumn>
                    </EditFormSettings>
    The Edit form appears, the user can edit the data, press the "Update" button, which triggers the 'OnUpdateCommand="RadGrid1_UpdateCommand"' to reflect the edited data in the grid and update the database.
    All this works fine.

    However, I need to be able to perform some validation on the data entered by the user before the Update sequence starts.
    If the validation fails, I want to display an alert with an error message, and with the WebUserControl form to remain displayed, with the data as entered by the user. Basically intercept the "update" sequence.

    As a result, I have been trying to figure out how to programmatically fire the "Update" comment from Javascript, and I can't figure out what I'm doing wrong.
    I've been basing my attempts on the following post:
    https://www.telerik.com/forums/calling-the-itemcommand-handler-from-javascript

    In my Grid.aspx code, I have the following Javascript code:
    <script>
        var varRadGrid;
        function GridCreated(sender, eventArgs) {
            varRadGrid = sender;
        }
        function CallUpdate() {
            var masterTable = varRadGrid.get_masterTableView();
            masterTable.fireCommand("Update", "");
        }
    </script>

    In my WebUserControl code, I have added a "Validate/update" button to call the "CallUpdate" function:
                <asp:Button ID="button" runat="server" Text="validate/update" OnClientClick="javascript:CallUpdate();" />

    I can trace through that all the various pieces appear to be working:
    1. When the grid initially loads, a reference to it is captured in varRadGrid.
    2. When the user presses the "Validate/update" button, the CallUpdate function is called, and it is able to reference the varRadGrid object.
    3. However, the code ' masterTable.fireCommand("Update", ""); ' appears to not do anything.
    Actually, that's not true - the WebUserControl form closes, but then is immediately redisplayed.

    Any edited data is not reflected back in the underlying grid - the "Update" command doesn't appear to be being fired.

    Any ideas? Help much appreciated!!

Back to Top