Friday, November 29, 2013

Age Calculator Using JavaScript.

Copy and Paste the Code in .aspx Page :


Convert English Language to Other Language Using Google API.

Just Copy and Paste the Code in .aspx Page :
Change HINDI language to other as per your requirement.
Note : Write the Language Name in Capital letter.  



How to Disable Cut, Copy and Paste in Text Box using JavaScript.

Just Copy and Paste the Code in .aspx page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tans.aspx.cs" Inherits="tans" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title> Disable Cut, Copy and Paste in Text Box using JavaScript</title>

<script type="text/javascript">
    $(document).ready(function() {
    $('#TextBox2').bind('cut copy paste', function(e) {
            e.preventDefault(); //disable cut,copy,paste
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
   <div>
   <asp:TextBox ID="TextBox2" runat="server" oncut="return false;" oncopy="return false;" onpaste="return false;"></asp:TextBox>

</div>
</form>
</body>

</html>


If you enjoy this post then please share.

Thursday, November 28, 2013

SQL Query for Find Highest Salary of a Employee.

Solution :

For  Highest Salary :

Select MAX(Salary) From EmployeeTable;

For 2Nd Highest Salary :

SELECT MAX(Salary) FROM EmployeeTable
WHERE Salary NOT IN (SELECT MAX(Salary) FROM EmployeeTable )

Find the nth highest salary using the TOP keyword in SQL Server :  

SELECT TOP 1 Salary
FROM (
      SELECT DISTINCT TOP N Salary
      FROM EmployeeTable
      ORDER BY Salary DESC
      ) AS Emp
ORDER BY Salary

Monday, November 25, 2013

Block Special Characters in JavaScript.

Copy and paste in <Head> section.

<script language="javascript" type="text/javascript">
        function DisableSplChars(e) {
            var keynum
            var keychar
            var numcheck
            // For Internet Explorer
            if (window.event) {
                keynum = e.keyCode
            }
            // For Netscape/Firefox/Opera
            else if (e.which) {
                keynum = e.which
            }
            keychar = String.fromCharCode(keynum)
            //List of special characters you want to restrict
            if (keychar == "!" || keychar == "@" || keychar == "#"
    || keychar == "$" || keychar == "%" || keychar == "^" || keychar == "&"
    || keychar == "*" || keychar == "(" || keychar == ")"
    || keychar == "<" || keychar == ">") {
                return false;
            }
            else {
                return true;
            }
        }


        function ValidateName(control, e) {
            if (control.value.length == 0 || !control.value.match(/[^\s]/)) {
                alert("Empty string detected.");
                control.focus();


                if (window.event) {
                    window.event.returnValue = false;
                }
                else {
                    e.preventDefault();
                }
            }
        }
    </script>

and, add in TextBox onkeypress="javascript:return DisableSplChars(event);"

<asp:TextBox ID="TextBox1" runat="server" onkeypress="javascript:return DisableSplChars(event);"></asp:TextBox>

Friday, November 22, 2013

Generate Random number in Asp.Net

Just Copy and paste the Code.

public static string GenerateRandomNumber(int Length)
    {
        
            string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
            Random randNumber = new Random();
            char[] chars = new char[Length];
            int allowedCharCount = _allowedChars.Length;

            for (int i = 0; i <= Length - 1; i++)
            {
                chars[i] = _allowedChars[Convert.ToInt32((_allowedChars.Length) * randNumber.NextDouble())];
            }
            return new string(chars);
        
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {

            string num = GenerateRandomNumber(5);
            Label1.Text = num;
        }
        catch
        {
        }
    }

Click Here For Demo

How to encrypt password in Asp.Net using MD5.

Just Copy and Paste the Code in your .aspx page.

(.aspx Page)

<div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" 
            onclick="Button1_Click1" />
       
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        
    </div>

(.aspx.cs page)

 public string Md5AddSecret(string sPassword)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] bs = System.Text.Encoding.UTF8.GetBytes(sPassword);
        bs = x.ComputeHash(bs);
        System.Text.StringBuilder s = new System.Text.StringBuilder();
        foreach (byte b in bs)
        {
            s.Append(b.ToString("x2").ToLower());
        }
        return s.ToString();
    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
        Label1.Text = Md5AddSecret(TextBox1.Text);

    }

Click Here For Demo

Make Your Computer Speak ( Using Notepad).

1. Copy and Paste the Below Code in Notepad.
2. Save the file in Name Saroj.vbs  , and close notepad.
3. Run the file. 

Dim message, saroj
message=InputBox("Write In the Box what you Want?","Speak to Me")
set saroj=CreateObject("sapi.spvoice")
saroj.Speak message


Have a Nice day.


Snake game in Html.

Just Copy and Paste the Code in Your HTML Page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>
<head>
<script type="text/javascript">

/****************************************************
*This game is available at http://www.sarojdotnet.somee.com
****************************************************/

Thursday, November 21, 2013

Always Running Marquee Text and Images Using JavaScript.

Copy and Paste the Code where you want to show the Marquee.


Show Welcome Message in your Page.

Just Copy and Paste in your page.

<body onload="position_at_top();expand()">

    <form id="form1" runat="server">

<div style="position:absolute;color:black" id="test"></div>

Flying Letters Using JavaScript

Just Copy and paste the Code in <Body> Section.

 <h2 id="fly" class="style1">Thanks for visiting  SarojAspDotnet...</h2>

<script type="text/javascript">
message = document.getElementById("fly").innerHTML; // $ = taking a new line
distance = 50; // pixel(s)
speed = 200; // milliseconds

var txt="",
 num=0,
 num4=0,
 flyofle="",
 flyofwi="",
 flyofto="",
 fly=document.getElementById("fly");

Show conformation Message Before Delete data using JavaScript .



Solution :

Just Add OnClientClick= "javascript:return confirm('Are you sure to delete this Data?');" in Button Control.
Copy and  paste  the Code in your Page.

      <asp:Button Text="Delete" runat="server" OnClick = "Submit" OnClientClick= "javascript:return confirm('Are you sure to delete this Data?');"/>