Here is our default.aspx source:
<%@ 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>Booking</title>
<style type="text/css">
div.fixed
{
width: 900px;
margin: 0px auto;
}
div.left
{
float: left;
width: 450px;
}
div.right
{
float: right;
width: 450px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="fixed">
<div class="left">
<p>Select your arrival date:</p>
<br />
<asp:TextBox ID="arriveTxt" runat="server"></asp:TextBox>
<asp:Calendar ID="arrive" runat="server"
onselectionchanged="arrive_SelectionChanged"></asp:Calendar>
</div>
<div class="right">
<p>Select your departure date:</p>
<br />
<asp:TextBox ID="departureTxt" runat="server"></asp:TextBox>
<asp:Calendar ID="departure" runat="server"
onselectionchanged="departure_SelectionChanged"></asp:Calendar>
</div>
<asp:CompareValidator ID="validator1" runat="server" ControlToValidate="departureTxt" ControlToCompare="arriveTxt" Type="Date" Operator="GreaterThan" Text="Please Select a Proper Date For Departure/Arrive"></asp:CompareValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
<asp:CustomValidator ID="validator2" runat="server" ControlToValidate="departureTxt" OnServerValidate="ServerDateValidation">You Must at Least Book for 2 Days</asp:CustomValidator>
<br />
</div>
</form>
</body>
</html>And this is our code behinde:
using System;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
departure.SelectedDate = DateTime.Now.Date;
arrive.SelectedDate = DateTime.Now.Date;
departureTxt.Text = departure.SelectedDate.ToShortDateString();
arriveTxt.Text = arrive.SelectedDate.ToShortDateString();
}
}
protected void departure_SelectionChanged(object sender, EventArgs e)
{
departureTxt.Text = departure.SelectedDate.ToShortDateString();
}
protected void arrive_SelectionChanged(object sender, EventArgs e)
{
arriveTxt.Text = arrive.SelectedDate.ToShortDateString();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void ServerDateValidation(object source, ServerValidateEventArgs args)
{
System.TimeSpan datediff = departure.SelectedDate - arrive.SelectedDate;
if (datediff.Days > 2)
args.IsValid = true;
else
args.IsValid = false;
}
}

No comments:
Post a Comment