Tuesday, 28 August 2012

alert function in java script


Alert Message in Java script



<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="javascriptalert.aspx.cs" Inherits="javascriptalert" %>
<!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>Untitled Page</title><script type ="text/javascript" language ="javascript">

function alertfunction() {alert (
'Hi');
}






</script></
head><
body onload ="alertfunction();"><form id="form1" runat="server"><div>
</div></form></
body></
html>

Login Page

.aspx page code

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

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <link href="design.css" rel="stylesheet" type="text/css" />
   

<script src="login.js" type="text/javascript"></script>

</head>
<body >

    <form id="form2" runat="server">
   
        <div id="background">
            <div id ="header">
            </div>
            <div id="content">
                <div id="content-header"></div>
                    <div id="login">
                            <div  id="labellogin">
                                <span id="spanlabeluser">
                                    <asp:Label ID="lbluser" CssClass ="lbl" runat ="server" text="User Name"
                                    ForeColor="Black"></asp:Label>
                                </span>
                                <span id="spanlabelpassword">
                                    <asp:Label ID="lblpassword" runat ="server" CssClass ="lbl"
                                    Text ="Password" ForeColor="Black"></asp:Label>
                                </span>
                            </div>
                            <div id="textlogin">
                                <span id="spantextuser">
                                    <asp:TextBox ID="txtusername" runat ="server" CssClass="txt"></asp:TextBox>
                                </span>
                                    <span id="spantextpassword">
                                    <asp:TextBox ID="txtpassword" runat ="server" CssClass="txt" TextMode="Password"></asp:TextBox>    </span>
                                    <span id="spanbutton">
                                  
                                     <input type ="button" id="buttonlogin" value ="Login" onclick ="callASHX()" class="btnlogin" />
                                    </span>
                                    <span id="spanclear">
                                     <input type ="button" id="button1" value ="Clear" onclick ="cleartext()" class="btnlogin" />
                                    </span>
                            </div>
                           
                    </div>
                <div id="content-footer"></div>
            </div>
            <div id="footer">
           
            </div>
        </div>
   
    </form>
  
</body>
</html>

Code for Handler.ashx
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;


public class Handler : IHttpHandler {
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["empConnectionString1"].ConnectionString.ToString());
    public void ProcessRequest (HttpContext context) {
        string strusername = HttpContext.Current.Request.QueryString[0].ToString();
        string strpwd = HttpContext.Current.Request.QueryString[1].ToString();
        con.Open();
        SqlCommand com = new SqlCommand("select count(*) from userlogin where userid=@userid and psd=@pass", con);
        com.Parameters.AddWithValue("@userid", strusername.Replace (" ",""));
        com.Parameters.AddWithValue("@pass", strpwd.Replace(" ", ""));
        object no= com.ExecuteScalar();
        context.Response.Write(no.ToString());
      
       
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

Coding for Design.css
body
{
          background-color:#ffeb95;
}
#background
{
          width:1600px;
          height:1050px;
          padding-top:0px;
          padding-bottom:0px;
          margin-right:auto ;
          margin-left:auto  ;
         
         
          }
#header
{
          width:1600px;
          height:173px;
          background-color:#ffeb95;
          margin-right:auto ;
          margin-left:auto  ;
          text-align :center ;
          font-weight:bold;
          font-size:14px;
         
}
#content
{
          width:1600px;
          height:704px;
         
          margin-right:auto ;
          margin-left:auto  ;
          background-color:#ffeb95;
          text-align :center ;
          color :Black ;
          font-weight:bold;
          font-size:14px;
         
         
}
#content-header
{
          width:1600px;
          height:200px;
         
          margin-right:auto ;
          margin-left:auto  ;
         
         
}
#content-footer
{
          width:1600px;
          height:200px;
         
          margin-right:auto ;
          margin-left:auto  ;
         
         
}
#footer
{
          width:1600px;
          height:170px;
          background-color:#ffeb95;
          margin-right:auto ;
          margin-left:auto  ;
          text-align :center ;
          font-weight:bold;
          font-size:14px;
         
}
#logo
{
          padding-left :0px;
          margin-left:0px;
          height:177px;
          width :300px;
         
         
}

.imagelogo
{
          width :300px;
          height :173px;
}

#login
{
          width:390px;
          height:300px;
          -moz-border-radius:40px;  /* for Firefox */
          -webkit-border-radius:40px; /* for Webkit-Browsers */
         
          background-color:#ffeb95;
          margin-right:auto ;
          margin-left:auto  ;
         
}
#labellogin
{
          width:110px;
          height:230px;
          float:left ;
          margin-top:35px;
left:25px;
position :relative;
          background-color:#ffeb95;
         
         
         
         
}
#leftpanel
{
          width:200px;
          height:704px;

          margin-top:0px;
left:0px;
position :relative ;
          border:solid 1px #ffeb95;
          background-color :#ffeb95;
          text-align :center ;
          font-weight:bold;
          font-size:14px;
         
         
         
         
}
#spanlabeluser
{
          width:100px;
          height:30px;
          float:left ;
          top:65px;
          left:5px;
          position :relative;
          background-color:#ffeb95;
         
}
.lbl
{
          font-family: Arial Courier New;
          font-weight:bold ;
          font-size:20px;
          color :White ;
}
.txt
{
          font-family: Arial Courier New;
          font-weight:bold ;
          font-size:15px;
          width :210px;
         
}
#spantextuser
{
          width:210px;
          height:30px;
          float:left ;
          top:65px;
          left:5px;
          position :relative;
          background-color:#ffeb95;
         
         
         
}
#spanlabelpassword
{
          width:100px;
          height:30px;
          float:left ;
          top:85px;
          left:5px;
          position :relative;
         
          background-color:#ffeb95;
         
}
#spantextpassword
{
          width:210px;
          height:30px;
          float:left ;
          top:85px;
          left:5px;
          position :relative;
          background-color:#ffeb95;
         
}
#spanbutton
{
          float:left ;
          top:100px;
          left:5px;
          width :100px;
          height :30px;
          position :relative;
          background-color:#ffeb95;

}
.btnlogin
{
          width :100px;
          height :30px;
          text-align:center;
          font-weight :bold ;
          vertical-align :middle;
         
}
#spanclear
{
          float:left ;
          top:100px;
          left:15px;
          width :100px;
          height :30px;
          position :relative;
          background-color:#ffeb95;
         
}
.btnclear
{
          width :100px;
          height :30px;
          text-align:center;
          font-weight :bold ;
          vertical-align :middle;
         
}
#textlogin
{
          width:225px;
          height:230px;
          float:left;
          left :25px;
          margin-top:35px;
          position:relative ;
          background-color:#ffeb95;
          margin-right:auto ;
          margin-left:auto  ;
         
         
}
Code for Login.js file
//function InitialXmlHttp() {
function Initial() {


    // Attempt to initialize xmlhttp object
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      
    }
    catch (e) {
        // Try to use different activex object
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
           
            xmlhttp = false;
        }
    }

    // If not initialized, create XMLHttpRequest object
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    xmlhttp.onreadystatechange = pagerequestCompleted;
}
function callASHX() {

    if (document.getElementById("txtusername").value == null || document.getElementById("txtusername").value == "") {
        alert('Enter Usr Name......');
        document.getElementById("txtusername").focus();
    }
   else if (document.getElementById("txtpassword").value == null || document.getElementById("txtpassword").value == "") {
        alert('Enter Password......');
        document.getElementById("txtpassword").focus();
    }
    else {
        Initial();
        xmlhttp.onreadystatechange = pagerequestCompleted;

        // HandlerSamplePlainText is the name of a HttpHandle file.
       
        xmlhttp.open("GET", "" + "Handler.ashx?usr=" + document.getElementById("txtusername").value + "&pws=" + document.getElementById("txtpassword").value, true);
        xmlhttp.send(null);
    }

}
function cleartext() {
    document.getElementById("txtusername").value= "";
    document.getElementById("txtpassword").value = "";
    document.getElementById("txtusername").focus();
}
function pagerequestCompleted() {


    if (xmlhttp.readyState == 4) {
        try {
             
          
            if(xmlhttp.responseText>0)
            {
                window.open("welcome.aspx");
                window.resizeTo(screen.width, screen.height);
            }
         else
         {
             alert("Invalid User");
             document.getElementById("txtusername").focus();
         }
 
        }
        catch (e) {
        }
    }
}


Welcome page.aspx

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

<!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>Untitled Page</title>
</head>
<body style="background-color:#ffeb95;">
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="200px"
            Text="Welcome"></asp:Label>
    </div>
    </form>
</body>
</html>