Display Textbox count on a Label

This solution will help you use asp Text box and a Label to display the count of characters,
Add below code on your Default.aspx,
<asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" 
     MaxLength="160" ></asp:TextBox>   
<asp:Label ID="lblCharacters" runat="server"></asp:Label>

Add below javascript code on your default.aspx,
<script language="javascript" type="text/javascript">
    function DisplayCount() 
    {
        var length = document.getElementById('<%=txtComments.ClientID%>').value.length;
        document.getElementById('<%=lblCharacters.ClientID%>').innerText = length;
    }
</script>

Add following code on your Page_load event,
txtComments.Attributes.Add("onkeypress", "javascript:return DisplayCount();");

After adding above code, you can see the count on the label when you type in the textbox.

Disable Right click on web page

How to disable right click on web page or If you want to protect your source code or many times programmers may need to disable right click on web page. You can copy below script code in between <head> and </head> tag.

<script type="text/javascript">
    var message="You Can't right click on this page!";
    function clickIE()
    {
        if (event.button==2)
        {
            alert(message);
            return false;
        }
    }

if (document.all&&!document.getElementById)
{
    document.onmousedown=clickIE;
}
document.oncontextmenu=new Function("alert(message);return false")
</script> 

Get Assembly Name

Sometimes you are asked to get/find Assembly name of a class.

You can use below code to get/find Assembly Name in VB.Net,
Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetAssembly(GetType(Class1))
Response.Write(assembly.GetName().Name)



You can use below code to get/find Assembly Name in C#,
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(Class1));
Response.Write(assembly.GetName().Name);


Here in above code Assembly.GetAssembly Method gets the currently loaded assembly in which the specified class is defined.

DateTime in different formats

Using DateTime.Tostring() method, you can display Date and/or Time based on your requirement.
Find the code below displaying Date in 24 different formats.

Response.Write("Displaying DateTime in 24 Different Formats....");

strFormat = dt.ToString("MM/dd/yyyy");
Response.Write("Format 1: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy");
Response.Write("Format 2: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm");
Response.Write("Format 3: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy hh:mm tt");
Response.Write("Format 4: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy H:mm");
Response.Write("Format 5: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy h:mm tt");
Response.Write("Format 6: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
Response.Write("Format 7: " + strFormat);

strFormat = dt.ToString("MM/dd/yyyy HH:mm");
Response.Write("Format 8: " + strFormat);

strFormat = dt.ToString("MM/dd/yyyy hh:mm tt");
Response.Write("Format 9: " + strFormat);

strFormat = dt.ToString("MM/dd/yyyy H:mm");
Response.Write("Format 10: " + strFormat);

strFormat = dt.ToString("MM/dd/yyyy h:mm tt");
Response.Write("Format 11: " + strFormat);

strFormat = dt.ToString("MM/dd/yyyy HH:mm:ss");
Response.Write("Format 12: " + strFormat);

strFormat = dt.ToString("MMMM dd");
Response.Write("Format 13: " + strFormat);

strFormat = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK");
Response.Write("Format 14: " + strFormat);

strFormat = dt.ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'");
Response.Write("Format 15: " + strFormat);

strFormat = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
Response.Write("Format 16: " + strFormat);

strFormat = dt.ToString("HH:mm");
Response.Write("Format 17: " + strFormat);

strFormat = dt.ToString("hh:mm tt");
Response.Write("Format 18: " + strFormat);

strFormat = dt.ToString("H:mm");
Response.Write("Format 19: " + strFormat);

strFormat = dt.ToString("h:mm tt");
Response.Write("Format 20: " + strFormat);

strFormat = dt.ToString("HH:mm:ss");
Response.Write("Format 21: " + strFormat);

strFormat = dt.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'");
Response.Write("Format 22: " + strFormat);

strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
Response.Write("Format 23: " + strFormat);

strFormat = dt.ToString("yyyy MMMM");
Response.Write("Format 24: " + strFormat);