RDLC report integration in ASP.NET Webforms using Object Data Source – SSRS

Standard

So in order to use SSRS reports in asp.net webforms application, following code comments should be taken care of:

1. Processing mode should be local in case of SSRS report
2. Object data source should be bind to class containing prototype of data access layer method
3. Empty data source object before each execution
4. set report parameter [if any]
5. set object data source parameter [if any]
6. set path of SSRS report
7. set method of object data source for processing of report
8. object data source id should be same as defined in client side / designer page [.aspx]
9. use same report data source which is used in SSRS report

Its done ūüôā

Client Side:

<rsweb:ReportViewer ShowWaitControlCancelLink=”false” ID=”ReportViewer”
runat=”server” Width=”100%” ProcessingMode=”Local”>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID=”objDataSource” runat=”server”></asp:ObjectDataSource>

 

Server Side:

protected void btnShowReport_Click(object sender, EventArgs e)
{
ReportViewer.LocalReport.DataSources.Clear();

//Processing mode should be local in case of SSRS report
ReportViewer.ProcessingMode = ProcessingMode.Local;

ReportViewer.Attributes.Add(“style”, “margin-bottom: 30px;”);
ReportViewer.ShowParameterPrompts = false;
ReportParameter[] reportParameterList = new ReportParameter[2];

//Object data source should be bind to class containing prototype of data access layer method
objDataSource.TypeName = “BusinessLogic.SampleBusinnessMethods”;
objDataSource.SelectParameters.Clear();

//Empty data source object before each execution
ReportViewer.LocalReport.DataSources.Clear();

//set report parameter [if any]
reportParameterList[0] = new ReportParameter(“id1”, 2, false);
reportParameterList[1] = new ReportParameter(“id2”, 3, false);

//set object data source parameter [if any]
objDataSource.SelectParameters.Add(“id1”, TypeCode.Int32, “2”);
objDataSource.SelectParameters.Add(“id2”, TypeCode.Int32, “3”);

//set path of SSRS report
agentMonitorReportViewer.LocalReport.ReportPath = Server.MapPath(“Report.rdlc”);

//set method of object data source for processing of report
objDataSource.SelectMethod = “SelectMethodName”;

var rptDataSource = new ReportDataSource();

//object data source id should be same as defined in client side / designer page [.aspx]
rptDataSource.DataSourceId = “objDataSource”;

//use same report data source which is used in SSRS report
rptDataSource.Name = “ReportDataSet”;
ReportViewer.LocalReport.DataSources.Add(rptDataSource);
ReportViewer.LocalReport.SetParameters(reportParameterList);
ReportViewer.DataBind();
ReportViewer.LocalReport.Refresh();
}

Advertisements

Executing Web Method of ASP.NET Webforms using AngularJS services

Standard

The code written in legacy asp.net web application using webforms c# can be bit tricky to change into angualrJS application, however below angular factory method help to execute a server side WebMethod, method type can be changes to Get or Post as per need:

var app = angular.module('Sample', ['ngRoute']);

app.factory('appFactory', function ($templateCache, $http) {
    var factory = {};
    factory.populateData = function (webMethodUrl, parameterList) {
        return $http({
            method: "POST",
            url: window.location.protocol + '//' + window.location.host + 
                 window.location.pathname + webMethodUrl,
            data: parameterList,
            headers: { "Content-Type": "application/json" },
            responseType: 'json',
            cache: $templateCache
        });
    };
    return factory;
});

Performance Enhancement in asp.net [Client Side]

Standard

Performance Enhancement

1. Minify Resources (HTML, CSS, and JavaScript):¨

Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser – e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so on.

2. Enable Compression:

¨All modern browsers support and automatically negotiate gzip compression for all HTTP requests. Enabling gzip compression can reduce the size of the transferred response by up to 90%, which can significantly reduce the amount of time to download the resource, reduce data usage for the client, and improve the time to first render of your pages.

Solution:

¨All excel templates/uploaded files etc in application

3.Optimize Images:

¬®Images often account for most of the downloaded bytes on a page. As a result, optimizing images can often yield some of the largest byte savings and performance improvements: the fewer bytes the browser has to download, the less competition there is for the client’s bandwidth and the faster the browser can download and render content on the screen.

Solution

¨Sprites
¨Save Image as font [using @font-face]
¨Using SVG’s [bit controversial]

4.Optimize CSS Delivery:

¨Before the browser can render content it must process all the style and layout information for the current page. As a result, the browser will block rendering until external stylesheets are downloaded and processed, which may require multiple roundtrips and delay the time to first render.

¨If the external CSS resources are small, you can insert those directly into the HTML document, which is called inlining. Inlining small CSS in this way allows the browser to proceed with rendering the page.

¨If the amount of data required exceeds the initial congestion window, it will require additional round trips between your server and the user’s browser. For users on networks with high latencies such as mobile networks this can cause significant delays to page loading.

5. Reduce the size of the above-the-fold content:

Solution:

To make pages load faster, limit the size of the data (HTML markup, images, CSS, JavaScript) that is needed to render the above-the-fold content of your page. There are several ways to do this:

¨Structure your HTML to load the critical, above-the-fold content first

¨Reduce the amount of data used by your resources

6.Remove Render-Blocking JavaScript:

¨Before the browser can render a page it has to build the DOM tree by parsing the HTML markup. During this process, whenever the parser encounters a script it has to stop and execute it before it can continue parsing the HTML. In the case of an external script the parser is also forced to wait for the resource to download, which may incur one or more network roundtrips and delay the time to first render of the page.

Solution:
¨Inline JavaScript [if few lines of code]
¬®<script async src=”my.js”>

7. Working with the DOM:

¬®Working with the DOM can cause browser reflow, which is the browser’s process of determining how things should be displayed. Directly manipulating the DOM, changing CSS styles of elements, and resizing the browser window can all trigger a reflow. Accessing an element’s layout properties such as offsetHeight and offsetWidth can also trigger a reflow. Because each reflow takes time, the more we can minimise browser reflow, the faster our applications will be.

function addAnchor(parentElement, anchorText, anchorClass)

{

var element = document.createElement(‘a’); parentElement.appendChild(element);

element.innerHTML = anchorText;

element.className = anchorClass;

}

Solution

function addAnchor(parentElement, anchorText, anchorClass)

{

var element = document.createElement(‘a’);

element.innerHTML = anchorText;

element.className = anchorClass;

parentElement.appendChild(element);

}

8. Avoid Plugins:

¨Plugins help the browser process special types of web content, such as Flash, Silverlight, and Java. Most mobile devices do not support plugins, and plugins are a leading cause of hangs, crashes, and security incidents in browsers that provide support.

Solution:

¨Use HTML5
¨Removal of activeX control from application

 

Dev Tool: Client Side Performance Evaluation

Page Speed Insight [Extension by Google Chrome]
¨Minimise payload
¨Minimise delay in page load
¨Other

Notes prepared From Google Blog

Ten Simple Tips to Improve Performance of an ASP.NET Website

Standard
Tips to improve the performance of ASP.NET web applications

Introduction

In this tip, we will look at various aspects of improving the performance of ASP.NET web applications.

Performance is an important aspect of the modern day web application development. Here are some tips that you can consider while making a better performing website.

1. Upgrade Your ASP.NET Framework

Check your .NET framework. If you can upgrade your site to use .NET 4.5, then it has some great performance optimizations. .NET 4.5 has a new Garbage Collector which can handle large heap sizes (i.e., tens of gigabytes). Some other improvements are Multi-core JIT compilation improvements, and ASP.NET App Suspension. These optimizations do not require code changes.

2. Caching

  1. Use output caching ‚Äď Use output caching for regularly used views or pages which have no dynamic updates. The easiest way to implement cache on MVC view is to add an [OutputCache] attribute to either an individual controller action or an entire controller class. Here is a controller action Index() that will be cached for 15 seconds.
    [OutputCache(Duration = 15, VaryByParam = "None")]
    public ActionResult Index(string Id)
    {
    
    }
  2. Use Data caching – Reduces the database or the disk I/O by caching the regularly used data to in-memory cache. This avoids repeated queries for data, and it can improve performance and scalability. In addition, caching makes data available when the data source is temporarily unavailable. The .NET Framework provides classes that enable you to use caching facilities in ASP.NET applications. These classes are defined in the System.Runtime.Caching namespace.

3. Always keep CSS and JavaScript External

Never add any JavaScript or inline style information within the views. That would regenerate the view each time and you would miss out on the benefits of the Caching. Hence always keep JS and CSS as separate files and add them as links in the view.

4. File Compression

There are often requests to the web server with lot of static content. These contents can be compressed thereby reducing the bandwidth on requests. The following setting is only available in II7 and later.

<configuration>  
    <system.webServer>    
        <urlCompression doStaticCompression=&rdquo;true&rdquo;       doDynamicCompression=&rdquo;true&rdquo; />  
    </system.webServer> 
</configuration>

The urlCompression name sounds strange but it is not really the compressing of URLs. It means compressing or gzipping the content that is sent to the browser. By setting to true/enabling, you can gzip content sent to the browser while saving lots of bandwidth.

5. Bundling and Minification

The custom CSS files and the JavaScript files should be bundled into a single large file (reduces the number of HTTP requests) and also minified (reduces the size of the data transferred over the wire).

6. CDN (Content Delivery Network)

All the 3rd party JavaScript files such as JQuery, Knockout should always use the CDN instead of the web application server. CDN Servers are dedicated to deliver the static content and is always faster than your own host. There is a very high probability that the client (browser) would have already cached the JavaScript as part of other web application since most of them use the same CDN URL.

7. Control Image Requests

There are couple of ways to do this.

  1. Image sprite – With image sprite, you can combine multiple different images into a single large image. Then use CSS to reposition those images within the site.
  2. Base64 Data URIs – With this option, you would never make any requests to the server to obtain any images.

8. Script Rendering Order

Move the script tags <script> to the very bottom of the page. The reason this is important is because during the rendering, when the browser comes across a <script> tag, it stops to process the script and then moves ahead. If you put the script tags at the bottom of the page, the page/HTML will render faster and the scripts can execute after the DOM elements have loaded. Sometimes moving the script to the bottom of the page is not possible as some DOM elements or CSS may depend on these scripts, so they can be rendered. In such cases, you could move those scripts further up the page.

There are some other ways:

  1. defer attribute
    <script src=&rdquo;some.js&rdquo; defer>
    
    </script>

    Using the defer attribute, you can specify the script not to run until the page has been fully loaded.

  2. async attribute
    <script src=&rdquo;some.js&rdquo; async>
    
    </script>

    Using the async tag, the scripts will be run asynchronously, as soon as it is available.

9. Removing Default HTTP Modules in ASP.NET

ASP.NET has many http modules waiting for request to be processed and would go through the entire pipeline even if it’s not configured for your application.

All the default modules will be added in the machine.config place in‚Äú$WINDOWS$\Microsoft.NET\Framework\$VERSION$\CONFIG‚ÄĚ directory. One could improve the performance by removing those modules which you wouldn‚Äôt require.

10. Compile in Release Mode

Always set the build configuration to release mode for the website.

In this tip, we looked at some of the approaches that you can take to make optimized and better performing web sites. This included, reducing number of requests to the server, changes to the .NET framework, and compressing techniques.

 

About the Author

Jithin Geroge


United States United States