This is a migrated thread and some comments may be shown as answers.

How to Add a Custom Toolbar command

0 Answers 408 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Manny
Top achievements
Rank 1
Manny asked on 29 Jun 2009, 10:47 PM
Been working with Telerik Reporting for three days now, and not particularly pleased (no drilldown, not much direct supported event handling, would have done better to RadGrid this output...). Here, however, is how to add a control to the Telerik toolbar. I want a single generic "Report Viewer" that all my reports can leverage. One benefit is being able to have a central process for user input to control the report display. But the Telerik Reporting toolbar is missing a "height" parameter. And, no direct way I can find to add it. Eck.

Reflection and IE Dev Toolbar to the rescue. IE Dev Toolbar tells me that there exists a <div> entry named ctl_rptvw_ReportToolbar as a child of the report viewer (named "rptvw" in my ascx):

<%

@ Control Language="C#" AutoEventWireup="true" CodeBehind="TelerikReportViewer.ascx.cs"

 

 

Inherits="ArchG2.Portal.rg2SupportingControls.Misc.TelerikReportViewer" %>

 

<%

@ Register Assembly="Telerik.ReportViewer.WebForms, Version=3.0.9.430, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"

 

 

Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>

 

<

 

asp:HiddenField ID="hdnExplicitHeight" runat="server" Value="0" />

 

<

 

div id="telerikViewer">

 

 

<telerik:ReportViewer ID="rptvw" runat="server" Height="300px" Width="100%"

 

 

oninit="rptvw_Init">

 

 

</telerik:ReportViewer>

 

</

 

div>

So I override the oninit and start exploring with  debugger:

 

 

protected void rptvw_Init(object sender, EventArgs e)

 

{

 

string flag = "";

 

 

try

 

 

 

 

{

 

// find the toolbar

 

 

 

 

flag =

"locate_toolbar";

 

 

Control ctlToolbar = rptvw.FindControl("ReportToolbar");

 

 

if (ctlToolbar == null) throw new ApplicationException("No toolbar; new Telerik version?");

 

 

// this is reverse engineered from telerik; might work

 

 

 

 

flag =

"create_controls";

 

 

Table tblHeight = new Table();

 

tblHeight.ID =

"PageHeight";

 

tblHeight.CssClass =

"ReportToolbarGroup";

 

Abr.CodeLibrary.Utils.

Global.MergeCssStyleAttributes(tblHeight.Attributes, "float:left;");

 

tblHeight.CellPadding = 0;

tblHeight.CellSpacing = 0;

 

TableRow rowHeight = new TableRow();

 

rowHeight.ID =

"row";

 

 

TableCell cellHeight = new TableCell();

 

cellHeight.ID =

"cell";

 

 

Label lblHeight = new Label();

 

lblHeight.ID =

"lblHeight";

 

lblHeight.AssociatedControlID =

"txtHeight";

 

lblHeight.Text =

"Height: ";

 

_txtHeight =

new TextBox();

 

_txtHeight.ID =

"txtHeight";

 

_txtHeight.Width =

Unit.Parse("5em");

 

 

LinkButton btnResize = new LinkButton();

 

btnResize.ID =

"btnResize";

 

btnResize.Text =

"Resize";

 

btnResize.Click +=

new EventHandler(btnResize_Click);

 

flag =

"add_controls";

 

cellHeight.Controls.Add(lblHeight);

cellHeight.Controls.Add(_txtHeight);

cellHeight.Controls.Add(btnResize);

rowHeight.Cells.Add(cellHeight);

tblHeight.Rows.Add(rowHeight);

ctlToolbar.Controls.Add(tblHeight);

}

 

catch (Exception ex)

 

{

LH.error(

"Problem at ", flag, ": ", ex);

 

NotifyError(

"Report: " + ex.Message);

 

}

//try

 

 

 

 

}

 

Reflection at first told me that the first child of the ReportToolbar control is of type Telerik.ReportViewer.WebForms.PageNavigationGroup. Too bad that type is not directly supported--it must be a private class. So I instead use good old F12 in the IE browser to turn on Dev Toolbar and take a peek at what Telerik actually generated, which was this:

<table class="ReportToolbarGroup" id="ctl_rptvw_ReportToolbar_NavGr" style="float: left;" cellSpacing="0" cellPadding="0">

Ah, says I, if they can generate a table then I can too! Which led to the code above and a LinkButton. (I could not use a regular Button, *someone* <ahem> put a style of "visible: false !important" on the generated input control. But the LinkButton works great, I get notified, I can respond to requested height changes and Bob's Yer Unkl.

In my btnResize_Click event, I simply set the Height of the wrapped report control (which, btw, I load dynamically from an ASCX property name hyuck hyuck) and I get the effect I want.

Score: 1 for us, zero for them.

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Manny
Top achievements
Rank 1
Share this question
or