Click or drag to resize

addEventListener Method

Add event listeners to a PdfWebControlApi Class instance which raises when a specific PdfWebControl client-side event type is raised.

function addEventListener(type, listener);



Type: String

The type of listener. See PdfWebControlApi Events for list of all events.


Type: Function

The function to call when this event is raised.

Return Value

Type: Boolean

true if listener added successfully; otherwise, false.


Some types of events will return parameters indicating more about their state.

The scope of all returned events is the PdfWebControlApi Class which raised it. This means that this.Key (or any other method) can be called on the this object to operate on this same PdfWebControl.


Simple Example

var myApi = new PdfWebControlApi("PdfWebControl1"); // where "PdfWebControl1" is the ID (ClientID) assigned to the PdfWebControl instance
myApi.addEventListener("saving", function(){window.alert("We are going to cancel this save for " + this.Key() + "!"); return false;});

Full Example

This example illustrates how to use the JavaScript PdfWebControlApi Class to detect and interact with events in a PdfWebControl.

The following examples uses a ASP.NET page which as a PdfWebControl on it and a single code behind page.


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Save.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
<body style="margin:0px">
    <form id="form1" runat="server">
        <radPdf:PdfWebControl ID="PdfWebControl1" RunAt="server" Height="600px" Width="850px" 
          OnClientLoad="PdfAttachListeners();" />

        <script type="text/javascript">
            function PdfAttachListeners()
                //attach listeners
                (new PdfWebControlApi("<%=Me.PdfWebControl1.ClientID%>")).addEventListener("saved", function(){window.alert("Save complete event raised for " + this.getKey());});
                (new PdfWebControlApi("<%=Me.PdfWebControl1.ClientID%>")).addEventListener("printing", function(){window.alert("The print start event was raised. We are going to cancel it.");return false;});

VB Code Behind

Option Explicit On
Option Strict On

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            Me.PdfWebControl1.CreateDocument("test", System.IO.File.ReadAllBytes("C:\fw4.pdf"))

        End If
    End Sub
End Class

Notice the value of property "OnClientLoad" for PdfWebControl1.


This code will setup the PdfWebControlApi listeners when the PdfWebControl has loaded.

Note: Listeners can not be attached to a PdfWebControl before it is completely loaded. In most browsers, this event is fired after the page as loaded. This means that events listeners which you attempt to add inline or in the page's load event will likely not be properly attached. In most cases, it is recommended that you use the OnClientLoad property to prevent attempting to access the PdfWebControlApi before it is ready or other JavaScript runtime exceptions.

See Also