Products Technologies Demo Docs Blog Support Company

TX Text Control Web: Attaching Events to Ribbon Elements

The HTML5 Web editor and template designer that is part of TX Text Control .NET Server comes with a ready-to-use ribbon bar implementation. Thanks to the fact that this ribbon bar is completely designed with HTML and CSS, all elements can be styled and modified using CSS, if required. The pre-configured File ribbon menu can be also modified and customized. Below is a screenshot that shows the typical file menu: The Save menu item is disabled and will be enabled automatically…

TX Text Control Web: Attaching Events to Ribbon Elements

The HTML5 Web editor and template designer that is part of TX Text Control .NET Server comes with a ready-to-use ribbon bar implementation. Thanks to the fact that this ribbon bar is completely designed with HTML and CSS, all elements can be styled and modified using CSS, if required.

The pre-configured File ribbon menu can be also modified and customized. Below is a screenshot that shows the typical file menu:

TX Text Control Web: Attaching events to ribbon elements

The Save menu item is disabled and will be enabled automatically after a document has been loaded using the Load item or by loading a document using the server-side API.

But what if you only want to provide a Save menu item to the end user with your own custom, code-behind save code?

In this case, you can attach a Javascript event to the ribbon element using jQuery that does a post-back targeting a hidden button in an UpdatePanel. This is less complex than it sounds. This article describes this concept in detail.

Using jQuery, an event is attached to the first <a> element of the Save menu item with the client ID #fileMnuItemSave:

$("#fileMnuItemSave a:first").click(function () {
    __doPostBack(\'<% Response.Write(Button1.ClientID); %>\', \'\');
    return false;
            });

The __doPostBack function does a post-back for the complete page or only parts of it when the target object is placed in an UpdatePanel. For this reason, we will place a dummy Button control in an UpdatePanel of the ASPX page and set the display CSS property to hidden:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Button
            style="display: none;"
            ID="Button1"
            runat="server"
            OnClick="Button1_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

When the user clicks the ribbon menu item Save, a post-back triggers the OnClick event of the button:

protected void Button1_Click(object sender, EventArgs e)
{
    string data;

    TextControl1.SaveText(out data,
        TXTextControl.Web.StringStreamType.RichTextFormat);

    System.Web.UI.ScriptManager.RegisterClientScriptBlock(this,
        this.GetType(),
        "AlertBox",
        "alert(\'Your document has been saved.\');",
        true);
}

In this event, you can save the document using the API call SaveText or do additional logic such as storing the document in a database. In the above code, a client-side message box informs the user that the document has been saved properly.

TX Text Control Web: Attaching events to ribbon elements

Download the sample from GitHub and test it on your own.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Download ZIP

Open on GitHub

Open in Visual Studio

Requirements for this sample

  • Visual Studio 2012 or better
  • TX Text Control .NET Server (trial sufficient)

Reporting

The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.

See Reporting products

Related Posts

ASP.NETReportingHTML5

Creating Your First ASP.NET Reporting Application

This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.


ReportingHTML5Tutorial

Reporting Best Practices and How-To Guides

This article collection contains best practices and how-to guides for Text Control Reporting (MailMerge) and the HTML5 based rich text editor (Web.TextControl). Getting-Started and Basic Concepts…


ReportingHTML5Tutorial

HTML5 Technical Considerations - The Concept Explained

The HTML5 Web Editor consists of two parts: The ASP.NET server control Web.TextControl that provides the client-interface and user experience and the TX Text Control Web Server running as a…


ReportingHTML5Tutorial

TX Text Control Web: Customize the Ribbon Bar

The new HTML5 based editor requires no plug-ins, but pure HTML5 and CSS. Therefore, each element of the 'out-of-the-box' usable ribbon bar can be customized and removed, if required. This enables…


ASP.NETDocumentViewerHTML5

Creating an ASP.NET MVC DocumentViewer Application With Razor

Create a simple ASP.NET (MVC) application that uses the HTML5 document viewer.