【Stimulsoft Reports.Net教程】查看器工具栏上的自定义按钮
【下载Stimulsoft Reports.Net最新版本】
此示例项目演示了如何在Web查看器的工具栏上添加自定义按钮。您可以设置自定义按钮的标题和图标,并添加单击事件。 例如,在工具栏上添加自定义按钮并定义单击事件,在其中显示警报消息。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Custom_Button_on_the_Toolbar_of_the_Viewer.Default" %> <%@ Register assembly="Stimulsoft.Report.Web" namespace="Stimulsoft.Report.Web" tagprefix="cc1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Custom Button on the Toolbar of the Viewer</title> </head> <body> <form id="form1" runat="server"> <cc1:StiWebViewer ID="StiWebViewer1" runat="server" OnGetReport="StiWebViewer1_GetReport" /> </form> <script type="text/javascript"> ... </script> </body> </html>
要添加按钮,您可以使用简单的JavaScript代码。首先,使用位于Web查看器对象中的SmallButton()构造函数创建自定义按钮对象。接下来,获取工具栏按钮容器并插入按钮对象。
var customButton = jsStiWebViewer1.SmallButton("customButton", "Custom Button", "emptyImage"); customButton.image.src = "https://www.stimulsoft.com/favicon.png"; customButton.action = function () { alert("Custom Button Event"); } var toolbarTable = jsStiWebViewer1.controls.toolbar.firstChild.firstChild; var buttonsTable = toolbarTable.rows[0].firstChild.firstChild; var customButtonCell = buttonsTable.rows[0].insertCell(0); customButtonCell.appendChild(customButton);
示例代码的结果如下图所示: