Wednesday, June 1, 2011

Making ViewState Secure

One of the most common ways to store information is in view state. View State uses hidden
field that ASP.Net automatically inserts in the rendered HTML of a web page. View state
information is stored in a single jumbled string that looks like this:
As this value isn’t formated as clear text, many ASP.Net programmers assume that
their view state data is encrypted. Actually, view state information is simply patched
together in memory and converted to a Base54 string which is a special type of string that
is always acceptable in an HTML document because it does not include any special character.
A clever hacker could reverse-engineer this string and examine your view state data
in a matter of second.
To make your secure data temperproof you have to use encryption enabled. You can turn on
encryption for an individual page using the ViewStateEncryptionMode property of the page
directive:

Thursday, January 6, 2011

Count total working days between two days in T-SQL

Create a user defined scalar function:

CREATE FUNCTION [dbo].[udf_GetWorkingDays](@StartDate DATETIME,@EndDate DATETIME)
RETURNS INT
AS
BEGIN

DECLARE @CurDate DATETIME
DECLARE @i INT
DECLARE @days INT

set @i=1
set @days=0
while @i<=(DATEDIFF(dd, @StartDate, @EndDate))
begin
      set @CurDate=dateadd(day,@i, @StartDate)
      if(DATENAME(dw, @CurDate) != 'Friday' and DATENAME(dw, @CurDate) != 'Saturday')
      begin
            set @days=@days+1
      end

      set @i=@i+1
end

RETURN @days
END



Let's test now with following query:
 
select dbo.udf_GetWorkingDays('01/01/2011','01/31/2011') as TotalWorkingDays

 Result is: 22

Hope this will help others.

Sunday, October 24, 2010

Gridview RowEditing or RowDeleting event fires twice problem

Problem:
When working with ASP.Net Gridview control's RowEditing or RowDeleting events, it fires twice if image is used in Edit or Delete CommandField. Many ASP.Net developers face this problem while working with Gridview controls. There is many post in different forum on this problem.

Solution:
To solve this problem convert CommandField to TemplateField and add an ImageButton to show your Edit or Delete image.

Example Code:


<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/Image/admin/edit.gif" Text="Edit" />
ItemTemplate>
asp:TemplateField>

Thanks.

Tuesday, September 7, 2010

Introduction to Balanced Scorecard(BSC)


The balanced scorecard (BSC) is a strategic planning and performance management tool. It was originated by Drs. Robert Kaplan (Harvard Business School) and David Norton as a performance measurement framework. This added strategic non-financial performance measures to traditional financial metrics to give managers and executives a more 'balanced' view of organizational performance.
The balanced scorecard has evolved from its early use as a simple performance measurement framework to a full strategic planning and management system. It provides a framework that not only provides performance measurements, but helps planners identify what should be done and measured. It enables executives to truly execute their strategies.
 It is extensively used in business and industry, government, and nonprofit organizations worldwide to align business activities. It improves internal and external communications, and monitor organization performance against strategic goals.
It is perhaps the best known of several such frameworks.  It was widely adopted in English speaking western countries and Scandinavia in the early 1990s.
Perspectives
The four "perspectives" proposed were:
Financial: encourages the identification of a few relevant high-level financial measures. Timely and accurate funding data will always be a priority, and managers will do whatever necessary to provide it. In fact, often there is more than enough handling and processing of financial data. With the implementation of a corporate database, it is hoped that more of the processing can be centralized and automated.
Customer: Recent management philosophy has shown an increasing realization of the importance of customer focus and customer satisfaction in any business. These are leading indicators: if customers are not satisfied, they will eventually find other suppliers that will meet their needs.
Internal Business Processes: This perspective refers to internal business processes. Metrics based on this perspective allow the managers to know how well their business is running, and whether its products and services conform to customer requirements (the mission).
Learning and Growth: This perspective includes employee training and corporate cultural attitudes related to both individual and corporate self-improvement. In a knowledge-worker organization, people -- the only repository of knowledge -- are the main resource. In the current climate of rapid technological change, it is becoming necessary for knowledge workers to be in a continuous learning mode.



Balance Scorecard

Monday, July 26, 2010

Creating client script dynamically




In many cases, you can create the client script for your page declaratively, usually as a script block. However, you can also create client script dynamically. This is useful if the script depends on information that is available only at run time. For example, you might insert client script into a page that addresses a server control whose name (ID) is not known until the application runs, or you might create script that depends on values that you get from a user.
You can create and insert client script dynamically into a rendered page by calling methods of the ClientScriptManager class, such as the following:
·         RegisterClientScriptBlock, which inserts a script block at the top of the rendered page.
·         RegisterStartupScript, which inserts a script block at the end of the rendered page.
The following example shows how to add dynamically generated client script to the page. The code checks whether a check box named checkDisplayCount is selected. If so, the code performs the following tasks:
·         It creates a client script function that uses a span element to display the character count in a TextBox control named TextBox1.
·         It adds a client event to the TextBox control.
·         It generates the span element.
The code assumes that the page contains a check box named checkDisplayCount whose AutoPostBack property is set to true and a PlaceHolder control named PlaceHolder1.



void Page_Load(object sender, EventArgs e)
{
    if(checkDisplayCount.Checked)
    {
        String scriptText = "";
        scriptText += "function DisplayCharCount(){";
        scriptText += "   spanCounter.innerText = " + 
            " document.forms[0].TextBox1.value.length";
        scriptText += "}";
        ClientScriptManager.RegisterClientScriptBlock(this.GetType(), 
           "CounterScript", scriptText, true);
        TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");
        LiteralControl spanLiteral = new 
            LiteralControl("spanCounter\">");
        PlaceHolder1.Controls.Add(spanLiteral);
    }
}