Version:
  1. Scripts on pages with data

    Article: AN0001643 Updated: 09.11.2018 Displayed: 650x

    It is possible to use scripts on pages with data (Datas.aspx and DataDetail.aspx) for class or query. In this way you can easily extend by your required functionality:

    • you cab add a new button to the toolbar for execution of your actions
    • respond to actions on the page
    • add a new control to a page for displaying further information
    • influence column behaviour (hide the column or set it in read-only mode)

    Scripting is not intended for supressing ObjectGears system functionality, but for extension by your functions.

    Each event can be defined in the script only once. It is not wrong if some event is not defined. You can create further functions for better transparency. However, these functions cannot collide with event names.

    There are available following events for scripts:

    In Datas.aspx:

    Event Description
    OnLoad Event is triggered after loading the page on server. It corresponds to ASP.NET event OnLoad.
    OnCreateFilter Event is triggered after creating filtering object. Here you can influence searched records.
    OnPreRender Event is triggered after rendering the page on server. It corresponds to ASP.NET event OnPreRender.

    In DataDetail.aspx:

    Event Description
    OnLoad Event is triggered after loading the page on server. It corresponds to ASP.NET event OnLoad.
    OnAfterLoadColumns Event is triggered after loading the columns. Here you can influence, wheather they will be displayed or in read-only mode.
    OnBeforeBinding Event is triggered before setting up values from the entity (read from the database) into controls in the page. The event can be used for initialization of controls (e.g. list of combobox values).
    OnAfterBinding Event is triggered after finishing binding of data from the entity into controls. Use the event for the final set up of controls or set up of your controls.
    OnAfterSave Event is triggered after saving page data. In case of an error in the script saving data is not cancelled.
    OnPreRender Event is triggered after rendering the page on server. It corresponds to ASP.NET event OnPreRender.

    Description of events

    All the events are in the script defined in the same way, just with a different name of function.

    Example of event definition:

    function OnPreRender()
    {
        ...
    }

    Script objects

    There are various properties available available for various events. These objects are described in the following table.

    In Datas.aspx:

    Event Object Description
      OGModel Instance of current model.
      OGParentType Type of the displayed object - class or query.
      OGClassDef Instance of the displayed class.
      OGQuery Instance of the displayed query.
      OGIsArchiveMode Indication, wheather there are archived records displayed on the page.
    OnLoad OGControlOperations List of buttons displayed in the toolbar. The list contains only enabled buttons.
    OnLoad OGColumns List of columns displayed in the record list. The list contains only enabled columns.
    OnLoad OGFilter Filter object for class/query.
    OnCreateFilter OGDataRowFilter Instance of filter, by which records from the database will be read.
      OGPageSetting Properties of the whole page.

    In DataDetail.aspx:

    Event Object Description
      OGModel Instance of current model.
      OGParentType Type of the displayed object - class or query.
      OGClassDef Instance of the displayed class.
      OGQuery Instance of the displayed query.
      OGIsArchiveMode Indication, wheather there are archived records displayed on the page.
      int? OGDataRowId Id of the data record from the operational table.
      int? OGArchiveId Id of the data record from the archive table.
    OnPreRender OGControlOperations List of buttons displayed in the toolbar. The list contains only enabled buttons.

    OnAfterLoadColumns

    OnPreRender

    OGColumns List of columns displayed in form. The list contains only enabled columns.
    OnLoad
    OnAfterLoadColumns
    OnBeforeBinding
    OnAfterBinding
    OnAfterSave
    OGEditOptions Object for setup of record creation, save or deletion.
      OGPageSetting Properties of the whole page.

    You can disable record creation, saving or deletion on page  DataDetail.aspx by means of object OGEditOptions. It is possible only to disable these operations. It is not possible to enabůe these operations in case user does not have necessary access rights.

    Control elements

    It is necessary to know names of the controls in order to use them in scripts. The following table contains the list of available names.

    In Datas.aspx:

    Type Code of the control element Description
    ToolbarButton  backButton Button Back in the toolbar.
    HyperLinkButton newButton Button New in the toolbar.
    ToolbarButton reloadButton Button Reload in the toolbar.

    In DataDetail.aspx:

    Type Code of the control element Description
    HyperLinkButton  backButton Button Back in the toolbar.
    ToolbarButton deleteButton Button Delete in the toolbar.
    ToolbarButton saveButton Button Save in the toolbar.
    HyperLinkButton newButton Button New as in the toolbar.
    HyperLinkButton newButtonAsNew Button Back in the toolbar.
    HyperLinkButton archive Button Archive in the toolbar.
    HyperLinkButton archiveDetail Button Detail archive in the toolbar.

    Examples

    Inserting a control in the page

    The script inserts a button into the toolbar, that will display an information text after clicking on it.

    function OnLoad()
    {
        OGForm.Toolbar.CreateButton( 'b1', 'Button', './imagesdata/archive.png');
    }

    function b1_Click()
    {
        OGForm.SetSuccess( 'You have clicked on B1 button');
    }

    Set up of button Back

    You can suppress default behaviour of the button by its set up. You can change the text in the button, its icon, URL (used when clicking on button) and visibility.

    Set the properties in the event OnLoad.

    function OnLoad()
    {
        var b = OGForm.GetControl('backButton');
        b.Visible = true;
        b.Text = 'Back to start';
        b.NavigateUrl = 'Datas.aspx?CId=85';
    }

    Page properties settings

    function OnLoad()
    {
      OGPageSetting.PageTitle = 'My name of the page';
      OGPageSetting.BackgroundColor = 'red';
      OGPageSetting.PageKeyword = 'keyword,another key word';
      OGPageSetting.PageDescription = 'Page description';
    }

     
  2.    ---
    Your rating:
    Rated by users: 0x
  3. Top
SearchTitle
×