Translate

Wednesday, 8 July 2015

Key Down Events and Key press Events

Key Down Events
-----------------


<script type="text/javascript">
        $(document).ready(function () {
            $("#<%= txtcontactno.ClientID%>").keydown(function (e) {
                if (e.shiftKey)
                    e.preventDefault();
                else {
                    var nKeyCode = e.keyCode;
                    //Ignore Backspace and Tab keys      
                    if (nKeyCode == 8 || nKeyCode == 9)
                        return;
                    if (nKeyCode < 95) {
                        if (nKeyCode < 48 || nKeyCode > 57)
                            e.preventDefault();
                    }
                    else {
                        if (nKeyCode < 96 || nKeyCode > 105)
                            e.preventDefault();
                    }
                }
            });
        });
    </script>



Key press Events
-----------------
 <script type="text/javascript">

        $(document).ready(function () {
            //called when key is pressed in textbox
            $('#<%=txtcontactno.ClientID%>').keypress(function (e) {
                alert('hello');
                //if the letter is not digit then display error and don't type anything
                if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                    //display error message
                    //  alert('Please Enter ');
                    //  $("#errmsg").html("Digits Only").show().fadeOut("slow");
                    return false;
                }
            });
        });

    </script>
------------

Monday, 6 July 2015

sql alter drop rename column in the table

To add a column in a table, use the following syntax:
------------------------------
ALTER TABLE table_name
ADD column_name datatype

-----------------------------
To delete a column in a table, use the following syntax (notice that some database systems don't
allow deleting a column):
--------------------------------------
ALTER TABLE table_name
DROP COLUMN column_name
-----------------------------


To change the data type of a column in a table, use the following syntax:
--------------------------------------------
ALTER TABLE table_name
ALTER COLUMN column_name datatype


----------------------------------
To rename Column Name
-------------------------
EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN'

Thursday, 18 June 2015

get ip address in c#

 //using System.Net;
        string hostName = Dns.GetHostName(); // Retrive the Name of HOST  
        string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
        Response.Write("My IP Address is :" + myIP);



or
-------
string ip_address = Convert.ToString(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
   Response.Write("My IP Address is :" + ip_address);  

C#- different type of alert message in code behind

 string Message = "Pabitra you as Microsoft Employee !";
         ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Pabitra you as Microsoft Employee !');", true);
         ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + Message + "');", true);

         ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Pabitra you as Microsoft Employee !');", true);
         ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Message + "');", true);

         Response.Write(@"<script language='javascript'>alert('Pabitra you as Microsoft Employee ! ')</script>");
         Response.Write(@"<script language='javascript'>alert('"+Message+"')</script>");

         Page.ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox", "<script language='javascript'>alert('Pabitra you as Microsoft Employee !');</script>");
         Page.ClientScript.RegisterStartupScript(Page.GetType(),"MessageBox","<script language='javascript'>alert('" + Message + "');</script>");

         ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('Pabitra you as Microsoft Employee !')", true);
         ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('" + Message + "')", true);
        ////////////////
ClientScript.RegisterStartupScript(this.GetType(), "Email", "<script>GetEmail();</script>");
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('Please Enter Data')", true);

         ClientScript.RegisterClientScriptBlock(GetType(), "Email", "GetEmail();", true);
        //In Html Page
        <head>
        <script type="text/javascript" language="javascript">
         function GetEmail() {
             alert('hi');
         }
        </script>
    </head>
    ///////////////////////////

Wednesday, 17 June 2015

custom message in asp.nt

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnClick" runat="server" Text="Click Me" OnClick="btnClick_Click" />
    </div>
    </form>
</body>
</html>
---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnClick_Click(object sender, EventArgs e)
    {
        CustomPopup.Show(this.Page, "Hello Pabitra Microsoft");
    }
   
 
}
public static class CustomPopup
{
    public static void Show(this Page Page, String Message)
    {
        Page.ClientScript.RegisterStartupScript(Page.GetType(),"MessageBox","<script language='javascript'>alert('" + Message + "');</script>");
    }
}

c# Page.ClientScript.RegisterStartupScript

 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('Hello Mr Pabitra Now your eligible for join in microsoft');window.location.href=('Thanku.aspx');</script>");