3

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>
2
  • there's no need to have so much whitespace in your code, it just means people need to do a lot more scrolling than the amount of code justifies. Commented Mar 7, 2016 at 16:26
  • Rather than doing if ((rolesList.Contains("admin")) || (rolesList.Contains("Admin"))) you can just do if (rolesList.Contains("Admin", StringComparer.InvariantCultureIgnoreCase)) Commented Mar 7, 2016 at 16:54

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That works perfectly, so much simpler in c#.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.