none
How to generate report in ReportViewer without having to click Vew Report button?? RRS feed

  • Question

  • Hi,

     

    I have set up a ReportViewer to get a ServerReport and display it. I set up the param and the value I want it to have selected. But when I run the code, it displays the report prompt area with the Param to be selected and the View Report button. When I select and click it runs. But I want it to just run without interaction through ReportViewer. Is this possible?

     

    Thanks!!


    --ACG
    Thursday, March 25, 2010 1:01 PM

Answers

  • I think I see the problem.  After you set the parameter value, you then supply new credentials to ServerReport.  Changing authentication will result in a new session being established because sessions are tied to the user that created them.  So the session that existed at the time you set the parameter value is lost, along with that parameter value.  If you move the assignment of credentials to the same point that you specify the server URL, I bet it will work.

    • Marked as answer by ACG Wednesday, March 31, 2010 1:04 PM
    Wednesday, March 31, 2010 4:06 AM
    Moderator

All replies

  • Can you include your code?
    Cephas Lin This posting is provided "AS IS" with no warranties.
    Thursday, March 25, 2010 2:46 PM
    Moderator
  • Here it is, thanks!!

                    rptViewer.ProcessingMode = ProcessingMode.Remote;
                    rptViewer.ServerReport.ReportServerUrl = new Uri("http://rptserver/reportserver");
                    rptViewer.ServerReport.ReportPath = "/Reports/TestReport";
                    ReportParameterInfoCollection param = rptViewer.ServerReport.GetParameters();
    
                    ReportParameter[] rps = new ReportParameter[]
                                                {new ReportParameter(param[0].Name, "Hello Param!")};
                    
                    rptViewer.ServerReport.SetParameters(rps);
    
                    IReportServerCredentials netCred = new CustomReportCredentials("user", "pwd", "domain");
                    rptViewer.ServerReport.ReportServerCredentials = netCred;
    
                  
                    rptViewer.ServerReport.Refresh();
    


    --ACG
    Thursday, March 25, 2010 5:25 PM
  • The report will render automatically if all parameters and credentials are satisfied.  When you are about to render the report, if you call ReportViewer.ServerReport.GetParameters(), do any of the parameters have a state that is not ParameterState.HasValidValue?
    Monday, March 29, 2010 9:36 AM
    Moderator
  • Hi, thanks for your reply!

     

    I have checked the State and it equals "HasValidValue"

     

    Should there be another property set somewhere?

     

    This is my viewer tag:      <rsweb:ReportViewer ID="rptViewer" runat="server" Width="100%"  Height="100%">
          </rsweb:ReportViewer>

     

    Everywhere I read it says this should just work simply like this, but it is not.

     

    Thank you!


    --ACG
    Monday, March 29, 2010 11:59 AM
  • When you launch the report from Report Manager, does it prompt for parameters? Again, if all of the parameters are supplied by default (or provided) values, it should render without hesitation. Another approach is to use an "explorer" control on the form and pass in the URL that has the parameters and rendering options you want to use.

    __________________________________________________________________
    William Vaughn
    Mentor, Consultant, Trainer, MVP
    http://betav.com
    http://betav.com/blog/billva
    http://www.hitchhikerguides.net

    “Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)”

    Please click the Mark as Answer button if a post solves your problem!

    Monday, March 29, 2010 5:17 PM
    Moderator
  • Thanks for you reply! yes my parameters are provided:
        ReportParameter[] rps = new
     ReportParameter[]
    {new ReportParameter(param[0].Name, "Hello Param!" )};

    So it should work. I'm wondering, does the report definition itself need to have have something set?
    Maybe the parameter needs to be set to something??

    --ACG
    Monday, March 29, 2010 11:25 PM
  • When the viewer displays, do all of the parameters have values selected?  Sometimes a string parameter that allows blank values but has no default specified in the RDL.  It will therefore look like it has a value but doesn't until you click view report and submit the "blank" string to the server.

    To help narrow down what is causing the issue, will you try setting ReportViewer.ShowCredentialPrompts and ReportViewer.ShowParameterPrompts to false?  The report viewer will wait for input if something isn't satisfied.  But if you configure the viewer not to display the prompts, it will instead throw an exception since it is missing necessary information and has no way to get it.  The exception message may help in figuring out the issue.

    Tuesday, March 30, 2010 7:06 AM
    Moderator
  • There is only one parameter and it is a text param. When the viewer loads the parameter is not filled in. I unchecked Allow Nulls in the parameter settings and it still behaves the same way.

    When I set this:

    rptViewer.ShowCredentialPrompts = false;
    rptViewer.ShowParameterPrompts = false;

    I get this error: The 'mainParam' parameter is missing a value
    --ACG
    Tuesday, March 30, 2010 2:04 PM
  • Wondering if this may have something to do with it?

    The way I'm getting to the reportviewer is after I log in through ldap. I show a login form which authenticated with LDAP, then that form redirects to the main page with a cookie. The main page has the ReportViewer control.

    Although, now that i think about it, originally I didn't have this redirect and was going straight to the report with standard user/pwd auth.


    --ACG
    Tuesday, March 30, 2010 2:21 PM
  • Ah, yes. Simply declaring the parameters is not enough. Each has to have a Value set.

    __________________________________________________________________
    William Vaughn
    Mentor, Consultant, Trainer, MVP
    http://betav.com
    http://betav.com/blog/billva
    http://www.hitchhikerguides.net

    “Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)”

    Please click the Mark as Answer button if a post solves your problem!

    Tuesday, March 30, 2010 4:33 PM
    Moderator
  • Yes, i am doing that:

    ReportParameter[] rps = new
     ReportParameter[]
    {new ReportParameter(param[0].Name, "Hello Param!" )};

    rptViewer.ServerReport.SetParameters(rps);

    --ACG
    Tuesday, March 30, 2010 9:45 PM
  • I think I see the problem.  After you set the parameter value, you then supply new credentials to ServerReport.  Changing authentication will result in a new session being established because sessions are tied to the user that created them.  So the session that existed at the time you set the parameter value is lost, along with that parameter value.  If you move the assignment of credentials to the same point that you specify the server URL, I bet it will work.

    • Marked as answer by ACG Wednesday, March 31, 2010 1:04 PM
    Wednesday, March 31, 2010 4:06 AM
    Moderator
  • You're absolutely correct!! Thank you!

    I moved this line to the top of the method and voila!!

    IReportServerCredentials netCred = new CustomReportCredentials("user" , "pwd" , "domain" );rptViewer.ServerReport.ReportServerCredentials = netCred;

    This is a very subtle thing and I suggest it be documented somewhere.

     

    Thanks again Brian!


    --ACG
    Wednesday, March 31, 2010 1:04 PM