Razor function takes more load time than usercontrol function

127 Views Asked by At

I just trying to change my usercontrol function to razor function.but the page load time by using razor function is more than usercontrol function can any one know why this time taken.here is my razor code

 @inherits RazorFunction
@using System.Linq;
@using Composite.Data;
@using Atc.Data;
@using System.Web.UI.WebControls;
@using System.Collections.Generic;

@functions {
    public override string FunctionDescription
    {
        get  { return "Function for footer"; }
    }


}

<ul>
    <li>@@Copyright 2012 </li>
    @{
            using(DataConnection dCon =new DataConnection())
            {
            SitemapNavigator sn = new SitemapNavigator(dCon);

            PageNode p = sn.CurrentHomePageNode;

            List<PageNode> hiddenPages = dCon.Get<Page_Settings>()
                                       .Where(x => x.FooterNavVisibility == true).OrderBy(x => x.Position)
                                       .Select(x => sn.GetPageNodeById(x.PageId))
                                       .ToList<PageNode>();
foreach (var item in hiddenPages)
            {
    <li><a href="@item.Url">@item.Title</a></li>

}
            }
}
 <li>
           <!-- AddThis Button BEGIN -->
        <div class="addthis_toolbox addthis_default_style ">
        <a href="#" class="share"></a>
        <a class="addthis_button_compact"></a>
        <a class="addthis_counter addthis_bubble_style"></a>
        </div>

    </li>
</ul>
 <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-5008fecf0e8dcc29"></script>

enter image description here

1

There are 1 best solutions below

0
On

It could be that actual UserControl's execution time was accounted in the line "ASP.NET controls: PageLoad, EventHandling, PreRender", which currently takes 91 ms.

On a side note: now need to create new DataConnection/SitemapNavigator objects -> there are Data, and SitemapNavigator properties on the base class for the razor functions.

If you want to optimize it, you can f.e. cache the "hiddenPages" variable, and clear cache on Page or PageSettings data type changes.