I have an application that serves SSRS reports. A given report is accessed in the following way:
Upon clicking View Report, a postback is submitted to the report server with the user-defined parameters. I need to grab these user-defined parameters and parse them as a URL string.
I found this doc that gets me close to what I need. This method should allow me to grab all visible parameters and parse them myself, but I need hidden parameters as well.
I got it working. Fair warning: I'm new to ASP.NET so this is likely not an ideal solution.
I added an event handler to the report viewer control's code behind. This queries the execution log, grabbing the parameters selected most recently by the user. It is meant to be triggered when a button called "Save Report" is clicked. If you try to handle this with a
PreRender event handler it will fire before the row has a chance to insert into the database, giving you the result of the user's second most recent execution parameters.
Define the Button (.ascx file)
<asp:LinkButton ID="SaveReportButton" runat="server" title="Save this Report"></asp:LinkButton>
Add event handler to code behind (.ascx.vb file)
Protected Sub SaveReportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveReportButton.Click Dim conn As New SqlConnection(<connection string here>) Dim cmd As New SqlCommand("SELECT TOP 1 Parameters FROM [ReportServer].[dbo].[ExecutionLogStorage] WHERE <qualify on user, timestamp, etc. here>", conn) cmd.Parameters.AddWithValue(<query parameter here>) conn.Open() Dim result = cmd.ExecuteScalar() ' Prevents NullReferenceException from result.ToString() in case no result is found If (result IsNot Nothing) ' Redirect based on parameter string retrieved from log Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri & "?" & result.ToString()) End If conn.Close() End Sub
WebForm_PostBackOptions() is sparse, but a colleague has already done it this way so I followed suit
for consistency's sake because it works.