Thursday, October 16, 2014

How To Show A Message When DataList Is Empty

DataList doesn’t have EmptyDataTemplate like GridView or ListView, Here is how we can achieve use FooterTemplate in DataList

<FooterTemplate>
<asp:Label ID="lblEmpty" Text="No test types found." runat="server"
Visible='<%#bool.Parse((SearchValuesList.Items.Count == 0).ToString())%>'> </asp:Label>
</FooterTemplate>


Sunday, September 21, 2014

How To Encrypt Stored Procedure In SQL Server

There are some situations where business logics wants to hide the logic implementation, in those scenarios schema of the stored procedure can be encrypted.

Use AdventureWorks2008
go

CREATE PROCEDURE uspEncryptedPersonAddress
WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON
SELECT * FROM Person.Address
END


If some one try to view using sp_helptext this is what they see


The text for object 'uspEncryptedPersonAddress' is encrypted.

Thursday, September 11, 2014

How To Display Current Time on Page using Javascript

Here is the JavaScript function which will get current time in Military format.

<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('Showtime').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>

Sunday, August 24, 2014

How To Copy Content From a protected Webpage

Sometimes it is very annoying when you want to copy any news or article or anything that you want to save and when you right clicks on it but it shows “Right click disabled”. Here are some tips that can be useful on different browsers

For Mozilla FireFox:

Step 1: Open any website that have blocked your right click.
Step 2: Go to Tools>Options>Content
Step 3: Uncheck the box “Enable JavaScript”
Step 4: Click OK

For Internet Explorer:

Step 1: Open the site.
Step 2: Go to Tools>Internet options>Security
Step 3: Now Click on Custom Level
Step 4: Now find Scripting Section it will be around the end.
Step 5: Now disable Active Scripting.This will disable JavaScript and vbscript in your browser.
Step 6:Click on OK.

For Google Chrome:

Step 1: Open the site.
Step 2: Go to settings.
Step 3: Expand Show Advance settings, On Privacy tab.Click on Content Settings.
Step 4: Disable java script and open the website.

Tuesday, August 12, 2014

How to Parse datetime in multiple formats

Here is how we can parse different date formats get validated using one function.

In VB.NET

'''Validate method for Date format
  Private Function validateDate(ByVal strDate As String, ByVal strColumnName As String) As String
        Dim strError As String = ""
        Dim provider As CultureInfo = CultureInfo.GetCultureInfo("en-us")
        Dim formatStrings As String() = {"MM/dd/yyyy", "yyyy-MM-dd", "d"}
        Dim dateValue As DateTime
        Try
            If DateTime.TryParseExact(strDate, formatStrings, provider, DateTimeStyles.None, dateValue) Then
                strError = "Success"
            Else
                strError = "Failed"
            End If
        Catch ex As Exception

        End Try
        Return strError
    End Function

In C#

///Validate method for Date format
private string validateDate(string strDate, string strColumnName)
{
    string strError = "";
    CultureInfo provider = CultureInfo.GetCultureInfo("en-us");
    string[] formatStrings = {
        "MM/dd/yyyy",
        "yyyy-MM-dd",
        "d"
    };
    DateTime dateValue = default(DateTime);
    try {
        if (DateTime.TryParseExact(strDate, formatStrings, provider, DateTimeStyles.None, out dateValue)) {
            strError = "Success";
        } else {
            strError = "Failed";
        }

    } catch (Exception ex) {
    }
    return strError;
}

Add as many as formatters to the formatStrings array and use this funtion. Happy Coding ☺☻