InlineScript

in namespace DotVVM.Framework.Controls

Renders a script that is executed when the DotVVM framework is loaded.

Usage & Scenarios

Renders a script that is executed when the DotVVM framework is loaded.

Sample 1: Basic InlineScript

The content of the InlineScript control is rendered as javascript in the page.

The framework adds a global object dotvvm which can be used to access client-side features. You can use the following events fired by the framework.

  • init: Executed when the DotVVM scripts and all required resources are loaded and the viewmodel is applied to the page.
  • beforePostback: Executed before the postback is sent to the server.
  • afterPostback: Executed after the postback response is received from the server.
  • error: Executed when the postback fails due to a some error on a server.
  • spaNavigating: Executed when you leave some page in the SPA container.
  • spaNavigated: Executed when you enter some page in the SPA container.
<dot:InlineScript>
  dotvvm.events.init.subscribe(function() { alert("Page loaded"); });
</dot:InlineScript>

Sample 2: Custom Error Handler

If the postback fails, you can invoke your custom code - e.g. display a message to the user.

@viewModel DotvvmWeb.Views.Docs.Controls.builtin.InlineScript.sample2.ViewModel, DotvvmWeb

<dot:Button Text="Sample Button" Click="{command: NeverEverRunThis()}" />

<!-- put inline script anywhere in the page -->
<dot:InlineScript>
	
	dotvvm.events.error.subscribe(function(args) {
		alert("Custom error handler!");
		args.handled = true;
	});
</dot:InlineScript>
using System;
using System.Threading;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.builtin.InlineScript.sample2
{
    public class ViewModel
    {
        public void NeverEverRunThis()
        {
            throw new Exception("This method was called from View Model.");
        }

    }
}

Properties

Name Type Description Notes Default Value
property icon Dependencies String Gets or sets the comma-separated list of resources that should be loaded before this script is executed.
attribute
inner element
static value
bindable
default
dotvvm
property icon Script String
attribute
inner element
static value
bindable
default

HTML produced by the control