Saturday 22 March 2014

Control Webpart Visible/Enable using macro in Kentico

Leave a Comment
Simple post just to show how you can enable or visible the webpart in certain page. This is basically to avoid using many template. You can use only one template that have many webpart, and you can control visible/enable it using macro.


Macro Code

{% 
if(NodeAlias == "Search")
{
   return true;
}
else
{
 return false;
}
%}


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

How to track download file analytics in Kentico 7

Leave a Comment
Let say you create one Document Type in Kentico CMS, and inside the document type got one field for attachment. So you want to track/count how many time the document download using Web Analytic feature in Kentico.

First of all you need to enable the web analytic feature in  Kentico. Follow this link to read more about web analytic in kentico.

Here is the solution to track/count download file for a DocumentType Field.

A bit of customization is required to track all the downloaded files. The problem is that only CMS.File document type downloads are tracked by default. However, you can change that by going to the file:

\CMSPages\GetFile.aspx.cs

Within this file, around line 1268 or Find method LogEvent there is the following condition:

if (IsLiveSite && (file.FileNode != null) && (file.FileNode.NodeClassName.ToLower() == "cms.file"))

You have to alter it to the following one so all files are logged, not only files attached to a CMS.File document:

if (IsLiveSite && (file.FileNode != null) )

You can also add only your document type, it's up to you:

if (IsLiveSite && (file.FileNode != null) && ((file.FileNode.NodeClassName.ToLower() == "cms.file")) II (file.FileNode.NodeClassName.ToLower() == "custom.documenttype")))


Reference : Kentico Forum

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Create Navigation Using Kentico 7 Repeater Webpart

Leave a Comment
Kentico CMS for ASP.NET empowers marketers and developers in creating websites without limits. It's the ultimate solution for your website, store, community and on-line marketing initiatives.

Today i want to show how you can use Repeater Webpart to create one Navigation. On this post i will more focus on the Transformation.

Let say this is your navigation html code :

Navigation Html Code

<ul class="megamenu">  
  <li>
    <a href="#_" class="megamenu_drop">LEVEL ONE</a>
    <div class="dropdown_3columns dropdown_container">
      <ul class="dropdown_flyout">
        <li class="dropdown_parent">
          <a href="#_">LEVEL TWO</a>
          <ul class="dropdown_flyout_level">
            <li>
              <a href="#_">LEVEL THREE</a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
  </li>
</ul>


Repeater Navigation Webpart Configuration




Transformation Code

Level One

<%# IfCompare(DataItemIndex.ToString().Trim(),"0","","<ul class="megamenu"> ") 
<li ><a href="<%# GetDocumentUrl() %>"><%# Eval("DocumentName") %></a>

<cc1:CMSRepeater ID="rptnavleveltwo" runat="server" ClassNames="cms.menuitem" 
                       TransformationName="<transformation name>" 
                       WhereCondition="(DocumentMenuItemHideInNavigation = 0) AND 
                (Published=1) AND (NodeLevel = 2)" 
                      OrderBy="NodeOrder ASC"
                      NestedControlsID="rptnavlevelthree" /> 

Level Two

 <%# IfCompare(DataItemIndex.ToString().Trim(),"0","","<div class=\"dropdown_3columns dropdown_container\"><ul class=\"dropdown_flyout\">") %>  
                                <li><a href="<%# GetDocumentUrl() %>"><%# Eval("DocumentName") %></a>
                                    <cc1:CMSRepeater ID="rptnavlevelthree" runat="server" ClassNames="CMS.MenuItem" 
                                    TransformationName="<Transformation Name>" 
                                    WhereCondition="(DocumentMenuItemHideInNavigation = 0) AND (Published=1) AND (NodeLevel=3)" 
                                    OrderBy="NodeOrder ASC" />
                                </li> 
<%# IfCompare(this.DataRowView.DataView.Count.ToString().Trim(),(DataItemIndex + 1).ToString().Trim(),"","</ul></div>") %>      

Level Three

<%# IfCompare(DataItemIndex.ToString().Trim(),"0","","<ul class=\"dropdown_flyout_level\">") %>
<li><a href="<%# GetDocumentUrl() %>"><%# Eval("DocumentName") %></a></li>
<%# IfCompare(this.DataRowView.DataView.Count.ToString().Trim(),(DataItemIndex + 1).ToString().Trim(),"","</ul>") %>


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Wednesday 5 March 2014

Tips to Improve LINQ to SQL Performance

Leave a Comment
LINQ to SQL is a powerful technology that can do as much harm as good if it is mis-used. Here is how to get more out of your LINQ to SQL efforts.

Tip 1: Ditch the Extra Baggage with ObjectTrackingEnabled 

LINQ to SQL, by default, behaves like it's going on a every possibility. It carries every provision it thinks it'll ever need, and your application carries that extra weight. If you know you're only going for a short hike, why not tell it to leave the pack at home?

That's where the ObjectTrackingEnabled property of the DataContext comes in. By default this property is true, which causes LINQ to SQL to keep track of every change you make to your data in case you want to save those changes later. If you know you're only reading data and won't be changing it, I suggest setting this property to false. Then all of that change-tracking overhead goes away.

The performance boost does come at a small price, however. Deferred loading will no longer work. You'll have to use LoadWith or manually extract related data yourself using projections.

Tip 2: Slim Down Your Queries with Projections

Let's say I have a Customer table with 20 fields, but I'm only interested in three: FirstName, LastName, and Email. What do you suppose LINQ to SQL will do if I execute this code?

var customer =

    (from cust in dataContext.Customers

     where cust.ID == customerID

     select cust).Single();

var customerLite = new {

    customer.FirstName,

    customer.LastName,

    customer.Email

};


The answer is it'll happily issue a 'SELECT' statement asking for all 20 fields in the Customer table so it can populate every field of the Customer entity it gives me back (even though I only care about three fields). That seems a bit wasteful, don't you agree?

Now suppose I re-wrote the code to look like this:

var customerLite =

    (from cust in dataContext.Customers

     where cust.ID == customerID

     select new {

        customer.FirstName,

        customer.LastName,

        customer.Email

     }).Single();


This time LINQ to SQL will issue a 'SELECT' statement asking only for the three fields I care about because I gave it enough information before it executed the query to know specifically what I wanted.

The technique I used in the second example is called projecting (or shaping) the data. Using an anonymous type, I tell LINQ to SQL exactly what I'm interested in, and that's all it asks for. For a single customer record this likely won't make a big difference, but if I'm retrieving a list of thousands or millions of customer records, the performance gain will be significant.

One real-world scenario where I've found this technique helpful is in returning data from a WCF service. I often don't want to return entire entities or an entire object graph from my service calls, so I project the data from LINQ to SQL into Data Transfer Objects (DTOs), which I send across the wire instead. These DTOs contain only the data I need and improve the performance of my service by cutting down on the payload I'm sending across the wire.

The only downside I've found with using projections is losing the ability to use the LINQ-generated entity classes (like the Customer class for customer records). This means I lose some entity-dependent features like deferred loading of child entities and state tracking. Since I tend to use projections mostly when I'm pulling lots of records for display or analysis purposes (and not for updating data), I'm generally okay with that tradeoff

Tip 3: Optimize Your Optimistic Concurrency Checking

LINQ to SQL will help us ensure that multiple users working with the same record don't overwrite each other's changes. It does this by enabling optimistic concurrency checking on all database updates by default and alerting us if it detects we're trying to update a record that has changed since we last retrieved it.

To see how LINQ to SQL does this, take a look at the entities LINQ to SQL generates for you. You'll see that each property on an entity has an UpdateCheck attribute, which has possible values of Always, Never, and WhenChanged.

By default, UpdateCheck is set to Always, which means LINQ to SQL will check the value you're saving for that property against what's in the database. (The checking comes in the form of extra qualifiers added to the 'WHERE' clause of your update query.) If they're different, LINQ to SQL assumes the record has changed since you last retrieved it and throws a concurrency exception.

Unless you need optimistic concurrency checking in your application, I recommend setting UpdateCheck to Never for the properties on your entities. This will greatly speed up your queries by eliminating all the extra checking that is done during updates. For many applications, this "last write wins" type of approach is perfectly acceptable.

If, however, you do need optimistic concurrency checking in your application, then I suggest adding a column of type timestamp to each of your tables in SQL Server that you want checked. I often do this by adding a column called "RowVersion" to my tables. Then when LINQ to SQL generates an entity class from that table, it will automatically set the UpdateCheck property to Never for all properties in the entity and use the timestamp column in the table for concurrency checking instead.

Tip 4: Keep the Number of Parameters Down

LINQ to SQL always uses parameterized queries to prevent SQL injection attacks. For example, suppose I have a Product table I wish to query for a single product.

My LINQ query might look like this:

var query =

        from p in dataContext.Products

        where p.ProductID = 1

        select p;


And LINQ to SQL, in turn, will generate this:

SELECT [t0].[ProductID], [t0].[ProductName], [t0].[CategoryID]

FROM [Products] AS [t0]

WHERE [t0].[ProductID] = @p0


It added a variable called "@p0" which will be assigned a value of 1 when the query is run.

Now obviously this is a contrived example, and a simple query like this with a single parameter will run pretty quickly. However, I've noticed through real-world testing that the greater the number of parameters, the slower LINQ to SQL performs. This problem is especially likely to manifest itself if your LINQ query uses the Contains() method, which LINQ to SQL translates to a 'WHERE IN' clause that takes the form of 'WHERE IN (@p0, @p1, @p2, ... ).'

If you have a query that's performing slowly, check the number of parameters being generated by LINQ to SQL. Try to limit the number of parameters to around a dozen or so at most. There's no magic number, but I've seen noticeable delays in my applications as soon as I start getting a little over a dozen parameters or so in my queries.


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Saturday 1 March 2014

How to splitting huge ViewState size

Leave a Comment
When the ViewState in your page becomes very large it can be a problem since some firewalls and proxies will prevent access to pages containing huge ViewState sizes. For this purpose ASP.NET introduces the ViewState Chunking mechanism. So ASP.NET enables splitting of the ViewState's single hidden field into several using the MaxPageStateFieldLength property in the web.config section.

When the MaxPageStateFieldLength property is set to a positive number, the view state sent to the client browser is broken into multiple hidden fields.

Setting the MaxPageStateFieldLength property to a negative number (the default) indicates that the view-state field should not be separated into chunks. Setting the MaxPageStateFieldLength to a small number may result in poor performance.

Sample ViewState before:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"value="/wEPDwUKLTk2Njk3OTQxNg9kFgICAw9kFgICCQ88KwANAGQYAQUJR3Jp
ZFZpZXcxD2dk4sjERFfnDXV/hMFGAL10HQUnZbk=" />


Then set in web.config:

<pages maxPageStateFieldLength="40">


Sample ViewState After :

<input type="hidden" name="__VIEWSTATEFIELDCOUNT" id="__VIEWSTATEFIELDCOUNT"value="3" />
<input type="hidden" name="__VIEWSTATE"
id="__VIEWSTATE" value="/wEPDwUKLTk2Njk3OTQxNg9kFgICAw9kFgICCQ88" />
<input type="hidden" name="__VIEWSTATE1"
id="__VIEWSTATE1" value="KwANAGQYAQUJR3JpZFZpZXcxD2dk4sjERFfnDXV/" />
<input type="hidden" name="__VIEWSTATE2"
id="__VIEWSTATE2" value="hMFGAL10HQUnZbk=" /> 



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.