asp.net中的calendar控件问题
如图,我要让点击go图片时出现日历以选择日期,可是选择下个月时(图中圈起来的按钮)日历就消失了还得点一下go图片才会出现。我是想问怎么让选择完日期后才让日历消失呢?<%@...
如图,我要让点击go图片时出现日历以选择日期,可是选择下个月时(图中圈起来的按钮)日历就消失了还得点一下go图片才会出现。我是想问怎么让选择完日期后才让日历消失呢?
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void calEventDate_SelectionChanged(object sender, EventArgs e)
{
txtDay.Text = calEventDate.SelectedDate.ToString("d");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblResult.Text = "You Picked:" + txtDay.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function displayCalendar() {
var datePicker = document.getElementById("datePicker");
datePicker.style.display = "block";
}
</script>
<style type="text/css">
#datePicker
{
display:none;
position:absolute;
border:2px solid black;
}
.content
{
width:400px;
background-color:white;
margin:auto;
padding:10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<asp:Label ID="lblCalendar" Text="Event Day" AssociatedControlID="txtDay" runat="server" />
<asp:TextBox ID="txtDay" runat="server" />
<img src="Images/image1.png" onclick="displayCalendar()"/>
<div id="datePicker">
<asp:Calendar ID="calEventDate" OnSelectionChanged="calEventDate_SelectionChanged" runat="server" />
</div>
<br />
<asp:Button ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" runat="server" />
<hr />
<asp:Label Text="" runat="server" ID="lblResult" />
</div>
</form>
</body>
</html> 展开
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void calEventDate_SelectionChanged(object sender, EventArgs e)
{
txtDay.Text = calEventDate.SelectedDate.ToString("d");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblResult.Text = "You Picked:" + txtDay.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function displayCalendar() {
var datePicker = document.getElementById("datePicker");
datePicker.style.display = "block";
}
</script>
<style type="text/css">
#datePicker
{
display:none;
position:absolute;
border:2px solid black;
}
.content
{
width:400px;
background-color:white;
margin:auto;
padding:10px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<asp:Label ID="lblCalendar" Text="Event Day" AssociatedControlID="txtDay" runat="server" />
<asp:TextBox ID="txtDay" runat="server" />
<img src="Images/image1.png" onclick="displayCalendar()"/>
<div id="datePicker">
<asp:Calendar ID="calEventDate" OnSelectionChanged="calEventDate_SelectionChanged" runat="server" />
</div>
<br />
<asp:Button ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" runat="server" />
<hr />
<asp:Label Text="" runat="server" ID="lblResult" />
</div>
</form>
</body>
</html> 展开
2个回答
展开全部
web.config的<pages><controls>里增加<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="asp"/>,如下:
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="ass" namespace="AirSeaSolution.AirSeaWebControls.WebControls" assembly="AirSeaSolution.AirSeaWebControls" />
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="asp"/>
</controls>
</pages>
页面上这样写:
<tr>
<td class="cell_header" width="100">Event Day:</td>
<td class="cell_input" width="110">
<asp:TextBox ID="txb_time" runat="server"
EnableViewState="False"></asp:TextBox>
<asp:CalendarExtender ID="calendar1" runat ="server" TargetControlID="txb_time" Format="yyyy-MM-dd"></asp:CalendarExtender>
</td>
</tr>
后台代码这样取日期:
string Time = txb_time.Text.Trim();
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="ass" namespace="AirSeaSolution.AirSeaWebControls.WebControls" assembly="AirSeaSolution.AirSeaWebControls" />
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="asp"/>
</controls>
</pages>
页面上这样写:
<tr>
<td class="cell_header" width="100">Event Day:</td>
<td class="cell_input" width="110">
<asp:TextBox ID="txb_time" runat="server"
EnableViewState="False"></asp:TextBox>
<asp:CalendarExtender ID="calendar1" runat ="server" TargetControlID="txb_time" Format="yyyy-MM-dd"></asp:CalendarExtender>
</td>
</tr>
后台代码这样取日期:
string Time = txb_time.Text.Trim();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询