Alert events
When developing content, you may also need to use alerts that are sent back and forth between the client and the server. Alerts that originate on the client cannot be trusted, because the alert and the data in the alert could have been manually generated on the client. By default, any alert created on the client is not trusted, so alert handlers registered in the server-side scripting are not automatically run when the alert is sent from the client.
When an application needs to accept a client-generated alert, you can add a
call to context.RegisterClientAlertsFor()
in the
server-side script in OnScriptInitializing()
. This
allows the client-generated alert to flow to the server for processing in the
server-side alert handler.
context.RegisterClientAlertsFor(list of alert names)
:
This call is made in the
OnScriptinInitializing()
method in the server-side
handler.
OnAlert()
handler is called. If the name does not match,
the serve- side handler is not run. If the alert was sent from the server, the
OnAlert()
handler is run regardless of whether or not it
is in the list of client alert names.
parms.StopServerSideHandler()
API call from the
client. However regardless of this
StopServerSideHandler
setting, if the alert did not
come from the server and it is not in the list of accepted client alerts, the
alert will not be processed by the server.
OnAlert()
handlers in the server-side scripting also
will not fire for a specific alert if the alert was altered by a client script.
Alerts are considered altered by client script that passes along an alert in
one of these methods:
context.Alert...(context.GetEvent().GetName());
context.Alert...("eventname");
Alerts should instead be passed along in this fashion to not be considered altered:
context.Alert....(context.GetEvent())