sir,
I am new to ASP.Net in c#.
i have to use a single calendar for two text boxes i.e,Start date and End date with tow buttons start and end.How to code it?
sir,
I am new to ASP.Net in c#.
i have to use a single calendar for two text boxes i.e,Start date and End date with tow buttons start and end.How to code it?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
paiha paigaPosted Oct 30, 2008, 4:18 AM
Use this code in inline
<%
@ 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>Untitled Pagetitle> head><
body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged"> asp:Calendar> <asp:Button ID="Button1" runat="server" Text="Start Date" OnClick="Button1_Click" /> <asp:TextBox ID="TextBox1" runat="server">asp:TextBox> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="End Date" /> <asp:TextBox ID="TextBox2" runat="server">asp:TextBox>div> form> body> html>and use this below code in code behind of the ASPX page and see the result, it will fulfill your requirement.
using
System;using
System.Data;using
System.Configuration;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;public
partial class _Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
Calendar1.Visible =
false; if (!IsPostBack){
Button2.Enabled =
false;}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e){
if (TextBox2.Text == "" && TextBox1.Text == ""){
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
Button1.Enabled =
false;}
else{
TextBox2.Text = Calendar1.SelectedDate.ToShortDateString();
}
Calendar1.Visible =
false;}
protected void Button1_Click(object sender, EventArgs e){
Calendar1.Visible =
true;Button2.Enabled =
true;}
protected void Button2_Click(object sender, EventArgs e){
Calendar1.Visible =
true;TextBox2.Text =
"";}
}
Thanks and enjoy with this and try it in order to see the result.