Monday, May 23, 2011

Javascript FromDate to Date Validation

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function CompareDate(txtfrom, txtto) {
    var From = txtfrom.value;
    var To = txtto.value;
    var strSplitFrom = From.split('/')
    var myDateFrom = new Date();
    myDateFrom.setFullYear(strSplitFrom[2], strSplitFrom[1] - 1, strSplitFrom[0]); 
    var strSplitTo = To.split('/')
    myDateTo = new Date();
    myDateTo.setFullYear(strSplitTo[2], strSplitTo[1] - 1, strSplitTo[0]); 
    if (myDateFrom > myDateTo) { 
        alert("Start date can not greater than End date.");
        txtfrom.focus(); 
        return false;
    }
    else {
        return true;
    } 
}
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p><b>DD/MM/YEAR Format</b></P>
        From Date<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
        <br/>
        To Date 
        <asp:TextBox ID="txtto" runat="server"></asp:TextBox>
        <br/>
        <asp:Button ID="Button1" runat="server" Text="Click" OnClientClick="return CompareDate(txtfrom,txtto);" />
    </div>
    </form>
</body>
</html>
 
javascript1
 
 
 

Friday, May 20, 2011

Hide and Visible using Javascript

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

<!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>
<script language="javascript" type="text/javascript">
    function forRentClicked() {

        if (document.getElementById('<%=CheckBox1.ClientID%>').checked == true) {

            RadioButtonList1.style.display = 'block';

        }
        else {
            RadioButtonList1.style.display = 'none';
        }
    }  
    </script> 
</head>
<body>
    <form id="form1" runat="server">
    <div> 
    <asp:CheckBox ID="CheckBox1" runat="server" Text="Items" onClick="forRentClicked()" /> 
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" style="display:none;">
        <asp:ListItem>One</asp:ListItem>
        <asp:ListItem>Two</asp:ListItem>
        </asp:RadioButtonList>
</div> 

    </form>
</body>
</html>

 

output :

visible

How to "hide" or make "visible" in javascript when i "check or uncheck" a checkbox

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

<!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">
<script language="javascript" type="text/javascript">
    function forRentClicked() {

        if (document.getElementById('<%=CheckBox1.ClientID%>').checked == true) {

            div1.style.display = 'block';

        }
        else {
           div1.style.display = 'none';
        }
    }  
    </script> 
</head>
<body>
    <form id="form1" runat="server">
    <div> 
    <asp:CheckBox ID="CheckBox1" runat="server" onClick="forRentClicked()" /> 
</div> 
<div id="div1"> 
    <asp:Label ID="Label1" runat="server" Text="Rental rate per week:"></asp:Label> 
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
</div> 
    </form>
</body>
</html>

 

Output:

visible1

Make Enter Button As Tab Key

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

<!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 src="script/JScript.js" type="text/javascript"></script>

    <script type="text/javascript">
        function keypressed(e) {
            var intKey = (window.Event) ? e.keyCode:e.which;

            if (intKey == 13) {
                document.getElementById('<%=text2.ClientID %>').focus();
                return false;
            }

        }

        function keypressed2(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text3.ClientID %>').focus();
                return false;

            }
        }

        function keypressed3(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text4.ClientID %>').focus();
                return false;

            }
        }

        function keypressed4(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text5.ClientID %>').focus();
                return false;

            }
        }

        function keypressed5(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text6.ClientID %>').focus();
                return false;

            }
        }

        function keypressed6(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text7.ClientID %>').focus();
                return false;

            }
        }

        function keypressed7(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text8.ClientID %>').focus();
                return false;

            }
        }

        function keypressed8(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text9.ClientID %>').focus();
                return false;

            }
        }

        function keypressed9(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=text10.ClientID %>').focus();
                return false;

            }
        }

        function keypressed10(e) {
            var intKey = (window.Event) ? e.keyCode : e.which;
            if (intKey == 13) {

                document.getElementById('<%=DropDownList1.ClientID %>').focus();
                return false;

            }
        }

        function keypressed11(e) {
            var intKey = (window.Event) ? e.keyCode:e.which;
            if (intKey == 13) {

                document.getElementById('<%=Button1.ClientID %>').focus();
                return false;

            }
        }

        function Validation1() {
            if (document.getElementById('<%=DropDownList1.ClientID %>').value == "Select::") {
                alert('select DropDownList');
                       document.getElementById('<%=Button1.ClientID %>').focus();
                return false;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox  onkeypress="return keypressed(event)"  id="text1" runat="server" Width="200px" ></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed2(event)" id="text2" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed3(event)" id="text3" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed4(event)" id="text4" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed5(event)" id="text5" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed6(event)" id="text6" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed7(event)" id="text7" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed8(event)" id="text8" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed9(event)" id="text9" runat="server" Width="200px"></asp:TextBox><br/>
    <asp:TextBox onkeypress="return keypressed10(event)" id="text10" runat="server" Width="200px"></asp:TextBox><br/>
     <asp:DropDownList ID="DropDownList1" runat="server" onkeypress="return keypressed11(event)">
        <asp:ListItem>Select::</asp:ListItem>
        </asp:DropDownList><br/>
     <asp:Button ID="Button1" runat="server" OnClientClick="return Validation1();" Text="Button" OnClick="Button1_Click" />
<asp:Label id="lblMsg" runat="server" forecolor="Red" text="* Username must be alphanumeric with no special characters"></asp:Label>
    </div>
    </form>
</body>
</html>

Monday, May 9, 2011

Enter Key Acts As Tab Key using Javascript

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

<!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">
<script language="javascript" type="text/javascript">
function testing(event,number)

{
if( event.keyCode == 13 )

{
var wow = document.getElementById(number);

wow.focus();

}

}

</script>
    <title>Making enter key work as tab for Fire Fox</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    &nbsp;<asp:Label ID="Label1" runat="server"
            Text="Make enter key work as tab for Fire Fox"></asp:Label>
        <table class="style1">
            <tr>
                <td>

                    <asp:TextBox ID="TextBox2" runat="server" onkeydown="testing(event,2)"
                        TabIndex="1"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <input id="2" type="text" tabindex="3" onkeydown="testing(event,3)" /></td>
            </tr>
            <tr>
                <td>

                    <input id="3" type="text" tabindex="2" onkeydown="testing(event,'ab')" /></td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="ab" runat="server" onkeydown="testing(event,'cd')"
                        TabIndex="4"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="cd" runat="server" onkeydown="testing(event,'ef')"
                        TabIndex="10"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DropDownList ID="ef" runat="server" onkeydown="testing(event,'RadioButton1')">
                        <asp:ListItem>a</asp:ListItem>
                        <asp:ListItem>b</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:RadioButton ID="RadioButton1" runat="server" onkeydown="testing(event,'ListBox1')"/>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:ListBox ID="ListBox1" runat="server" onkeydown="testing(event,'TextBox1')"></asp:ListBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" onkeyup="testing(event,'Button1')"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" UseSubmitBehavior="false" runat="server" Text="Button" Width="166px" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Sunday, September 5, 2010

Javascript From Date,To Date Example





Wednesday, July 28, 2010

Bind the DropDownList On Selected IndexChanged based on the ID


Output :
Bind the DropDownList On Selected IndexChanged based on the ID





Table Design :
MASTERSITE
SELECT SITE_SITEID_ID, SITE_SITECODE_ID, STATE_STATEID_ID,
FROM MASTERSITE

MASTERSTATE
SELECT STATE_STATEID_ID, STATE_STATENAME_NM, STATE_SHORTNAME_CD
FROM MASTERSTATE



Stored Procedure :
Alter Procedure SelectSite
(
@STATE_STATEID_ID int
)
As
Select * from MASTERSITE where STATE_STATEID_ID = @STATE_STATEID_ID



CODE:
Default.aspx

StateName:
SiteCode:
::Select


Default.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default3 : System.Web.UI.Page
{

#region Declare
BOMaster objbomaster;
BLLMaster objbllmaster;
CommonBinding objcmnbinding;
DataSet ds;
#endregion

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bindddl();
// BindGV();
}
}

public void Bindddl()
{
objcmnbinding = new CommonBinding();


ddlState = objcmnbinding.CommonBindingDDL("SelectState", "STATE_STATENAME_NM", "STATE_STATEID_ID", ddlState);

}
//ddlState_SelectedIndexChanged
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
objbomaster = new BOMaster();
objbllmaster = new BLLMaster();
ds = new DataSet();
objbomaster.StateID = Convert.ToInt32(ddlState.SelectedItem.Value);
ds = objbllmaster.SelectSiteCode(objbomaster);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
ddlSiteCode.DataTextField = "SITE_SITEID_ID";
ddlSiteCode.DataValueField = "SITE_SITECODE_ID";
ddlSiteCode.DataSource = ds.Tables[0];
ddlSiteCode.DataBind();
ListItem itm = new ListItem("::Select::", "0");
ddlSiteCode.Items.Insert(0, itm);
//return ddlSiteCode;
}
else
{
ListItem itm = new ListItem("::Select::", "0");
ddlSiteCode.Items.Insert(0, itm);
}

}
catch (Exception ex)
{
lblmsg.ForeColor = System.Drawing.Color.Red;
lblmsg.Text = ex.Message.ToString();
}
}
}


DAL

#region SelectSiteCode
public DataSet SelectSiteCode(object ObjBOClass)
{
try
{
objbomaster = ((BOMaster)(ObjBOClass));
objsqlhelper = new sqlhelper();
objsqlhelper.ClearParameters();
objsqlhelper.CreateParameter("@STATE_STATEID_ID", objbomaster.StateID);
return objsqlhelper.ExecuteQueryWP("SelectSite");
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
#endregion


BLL


#region SelectSiteCode
public DataSet SelectSiteCode(object ObjBOClass)
{
try
{
return (DataSet)new DALMaster().SelectSiteCode(ObjBOClass);
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
#endregion


AppCode/CommonBinding.cs

#region DropDownListBinding
public DropDownList CommonBindingDDL(string SPName, string DataTextField, string DataValueField, DropDownList ddlName)
{
try
{
objbllmaster = new BLLMaster();
ds = new DataSet();
ds = objbllmaster.GetDataFromDatabase(SPName);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
ddlName.DataTextField = DataTextField;
ddlName.DataValueField = DataValueField;
ddlName.DataSource = ds.Tables[0];
ddlName.DataBind();
ListItem itm = new ListItem("::Select::", "0");
ddlName.Items.Insert(0, itm);
return ddlName;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
#endregion