Report Viewer in MVC3 - reportviewer

I have written a report in asp.net MVC 3 with the report viewer using a user control (ascx) in a partial View in the Report.cshtml(View). I'm having a problem with report viewer control when I run the application. When I have more than two pages and I want see the second or more page, I get "microsoft jscript runtime error '__eventtarget' is null or not an object".
The error is because there is postback. How can I fix this?

You're not going to be able to use the built in toolbar to navigate. (At least not without finding your own work around).
What I did was created my own bar right above my control and it simply sends an action ("First", "Last", "Next", "Previous") to an action on the controller to adjust the ReportViewer's CurrentPage Variable. (I keep tract of the current page through the session and set it in the user control ascx).

Related

ReportViewer 15.0.0.0 vertical scroll on opening a sub record

We have an MVC web application, and recently we migrated from Microsoft ReportViewer from 11.0.0.0 to 15.0.0.0 version.
We started having different issues in terms of UI, one of which is mentioned as below.
When we run the report from SSRS (SQL Server 2016), and click on the plus icon used to open the sub record (inner record), the vertical scroll bar maintains position and we can see the data clearly, as shown in below image
However, when the same report is run from MVC web application, using ReportViewer control, when we click on the plus button the scrollbar scrolls to the expanded icon and it does not gives good look and feel to end user. Sometimes the scroll even hide half of the current record. E.g. below is the screenshot when we run report from MVC web application using ReportViewer control. 1st image shows before clicking on the plus icon, and 2nd image shows after clicking on the plus icon.
Image-1
Image-2
Has anyone come across such situation? How can I avoid such scrolling on opening a sub record ?
Following is code I have used in .aspx file of which uses ReportViewer control

One or more data sources is missing credentials

I am implementing a series of rdlc reports on a webpage using a ReportViewer. When the report is initially generated is works fine but when I try to change the page of the report the following error is displayed:
"One or more data sources is missing credentials"
I have checked that the Data Source of the Local report is set correctly and the fact that the first page of the report is correctly displayed is proof of this.
When I export the report to a PDF or any other format it correctly includes all the report pages.
I have also tried implementing the PageNavigation event but this error is thrown before the event is called.
Does any one have any incite into this issue and what solution there may be?
Ok I found the the problem. I had a setting AsyncRendering set to false in order enable the reportviewer to stretch to the full width of the page.
Unfortunately this causes a postback and the enitre page is reloaded and obviously the datasource is lost.
Unfortunate as I will now have to manage the width of the reportviewer manually and it does not look great.
Anyway solution is to ensure AsyncRendering = true.

Reload/refresh page after postback. SharePoint, Visual Web Part (Sandboxed)

I have a visual web part (sandboxed) that visualize a form for adding sub-sites. When a sub-site is added its added in the navigation and in a DropDownlist (for delete purpose...).
My problem is that after post-back everything works fine, except i have to manually reload the page to see the new changes (both nav. and dropdownlist). Note that neither Response.Redirect or UpdatePanel will work i a sandboxed-solution.
Anyone got a solution to this problem?
When you perform a postback, your browser submits the contents of all web controls to the server. The server is stateless in this sense; the state of the control is actually stored in your browser. I would say your problem occurs because the web controls are not populated from SharePoint object model. Instead, the server uses the data received as the postback. Alternatively, the population might even happen, but the postback data will overwrite the contents of controls.
The solution is to refresh control data after the controls have been populated from the postback data. You could do this, for example, in the method OnPreRender. When OnPreRender is called, all the postback data has already been processed.
Try to add the following code in your webpart class.
protected override void OnPreRender(EventArgs args)
{
if (this.Page.IsPostBack)
{
// Repopulate controls here
}
}
The problem of this is, of course, that repopulation will kill the previous (postback) state of the controls. So, if you want to preserve the current value of a control (such as a dropdown selection), you must save it before repopulation and restore it manually.
To learn more about the page lifecycle in ASP.NET, see ASP.NET Page Life Cycle Overview.

SharePoint 2010: trying to understand life-cycle issues with visual web part

I am building a visual web part which has a number of user-configurable properties. The web part will display news items and, optionally, automatically switch to the next item after a defined pause.
The problem I'm having is that the user control part has a timer which fires events. These events reenter the user control (without going through the web part) and I see that when this happens the user control is in an unitialised state - i.e. the custom properties of the web part have not been applied. This causes the control to behave in it's default manner.
What am I doing wrong?
When you set property in your webPart, you need to bubble it down to the User control.
See creating custom properties for visual webparts:
http://patricklamber.blogspot.com/2010/05/how-do-i-create-custom-properties-in.html

Share Point Foundation 2010 - Failed to Start Workflow

I am using SharePoint Foundation (Sharepoint 2010) to develop a workflow in Visual Studio with an ASP.NET Workflow Initiation Form.
I use this form to set some properties on the share point list item on which the workflow instance is being started. Sometimes I get an Error message in the brwoser window, something like:
Error
Failed%20to%20Start%20Workflow
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 0b8e0b67-f824-4aa5-8316-424ada134f8d
Date and Time: 6/25/2010 10:59:17 AM
Go back to site
This behaviour seems intermittent. What's going on?
The problem is that the SharePoint workflow initiation form caches the workflow List Item on PageLoad, and when you make changes to the item between the page load and calling HandleStartWorkflow (i.e. clicking on the Start Workflow button), SharePoint freaks out that the item that you're talking about is different (the cached item) to the item that exists in Share Point (which incorporates the changes you've just made).
The general steps to reproduce the problem are:
Start the workflow so that the initiation form shows.
Change some property on the WorkflowProperties.Item
Call WorkflowProperties.Item.Update to save the changes to SharePoint
Call HandleStartWorkflow.
You will get the error.
The error may seem intermittent if some of the time the change to the workflow item properties is made in a separate page load 'session' to the session that the Start Workflow button is clicked. For example, if you PostBack some form data and then click the Start workflow button then everything works, because the PostBack happened and then the page was loaded.
But if you use an ASP TextBox OnTextChanged event, change the text and then click the Start Workflow button, the OnChanged event is fired AFTER the page is loaded with the old data, the data is changed to the new data and the workflow is started before the item data is re-loaded from SharePoint.
The fix is easy: Reload the workflow item data JUST before starting the workflow. This will cause your cached workflow item and the sharepoint version of the item to be the same, and share point will be happy.
In the "Workflow Initiation Code" region, change:
Private Sub StartListWorkflow()
Dim association As SPWorkflowAssociation = workflowList.WorkflowAssociations.Item(New Guid(associationGuid))
Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData)
SPUtility.Redirect(workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current)
End Sub
to
Private Sub StartListWorkflow()
'Re-initialize the workflow parameters, particularly the workflowListItem, in case it has been changed since page load.'
InitializeParams()
Dim association As SPWorkflowAssociation = workflowList.WorkflowAssociations.Item(New Guid(associationGuid))
Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData)
SPUtility.Redirect(workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current)
End Sub
And everything should start working again.
The same message you will get if you try to start workflow (through the custom init form) which is already running on the item. Solution here would be to check the state of the workflow on the item.