Reputation: 581
I know how to use a String variable from code to behind and say display that string on the web page. What I want to do is similar except that instead of displaying a string, I want to pass the boolean value from code behind, to the ASP.NET page so that its' true / false value can control the Print button (true / false) in the ReportViewer. My Diagnostic works in that it displays the string "True" or "False", which ever is correct. The "ShowPrintButton" and "ShowExportControls" just don't work though and the buttons are not enabled. What do I need to do here? I think the value is being passed but perhaps it's being passed as a string and I need to do something to make it pass as a Boolean....
Here's the code ...
Code Behind:
//Variables
public Boolean exportEnabled { get; set; }
public Boolean printEnabled { get; set; }
//Page Load
protected void Page_Load(object sender, EventArgs e)
{
// Add a handler for SubreportProcessing
reportViewerPrintAndExport.LocalReport.SubreportProcessing +=
new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
if (!IsPostBack)
{
// Display the report
DisplayReport(Session[SessionKeys.KEY_CERT_NO].ToString(), (CalibrationType)Session[SessionKeys.KEY_CERT_TYPE]);
}
DataBind();
}
private void DisplayReport(string certNo, CalibrationType calType)
{
string[] rolesList = Roles.GetRolesForUser();
//manage print and export buttons.
if ((rolesList.Contains("admin")) || (rolesList.Contains("Admin")))
{
exportEnabled = true;
printEnabled = true;
}
else if ((rolesList.Contains("Operator")) || (rolesList.Contains("operator")))
{
exportEnabled = false;
printEnabled = false;
}
}
aspx:
<!-- DIAGNOSTIC -->
<asp:label runat="server" text="-" /><asp:label runat="server" text="<%# printEnabled %>" /><asp:label runat="server" text="-" />
<asp:Panel ID="ReportPanelPrintAndExport" runat="server" HorizontalAlign="Left">
<!--Why does this not work? -->
<rsweb:ReportViewer ShowPrintButton="<%# printEnabled %>" ShowExportControls="<%# exportEnabled %>" ID="reportViewerPrintAndExport" runat="server" Height="100%" Width="100%"
ShowBackButton="False" ZoomMode="FullPage"
ShowRefreshButton="False" ProcessingMode="Local">
</rsweb:ReportViewer>
Upvotes: 3
Views: 5008
Reputation: 3009
In your code behind simply set that property wherever you want to
if ((rolesList.Contains("admin")) || (rolesList.Contains("Admin")))
{
reportViewerPrintAndExport.ShowPrintButton = true;
reportViewerPrintAndExport.ShowExportControls = true;
}
else if ((rolesList.Contains("Operator")) || (rolesList.Contains("operator")))
{
reportViewerPrintAndExport.ShowPrintButton = false;
reportViewerPrintAndExport.ShowExportControls = false;
}
There is no need to try to do this on the client side.
Upvotes: 5