我正在使用jQuery DatePicker控件。控件显示正常,但我无法在我的代码页面后面获取所选值。我尝试使用以下方法捕获用户选择的值:DateTime StartDt = Convert.ToDateTime(Request.Form [“datepicker”]);用户有几个控件可供选择,然后点击提交。
提交后,当我检查StartDt的值时,它是:01/01/0001 00:00:00 AM
ASPX页面:
<%@ Page Title="Fox Cities Restaurant Guide-Food Events" Language="C#" MasterPageFile="~/main_master.Master" AutoEventWireup="true" CodeBehind="Events.aspx.cs" Inherits="FCGuide.Events" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="Styles/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#datepicker").datepicker();
});
</script>
<style type="text/css">
#datepicker
{
width: 110px;
height: 19px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="defaultEvent">
<div id="EventNav">
<div id="EventType" class="EventNavDivs">
<span class="EventTitle">Event Type</span> <br />
<asp:DropDownList ID="ddlEventType" runat="server">
<asp:ListItem>Any Event</asp:ListItem>
<asp:ListItem>Art Shows</asp:ListItem>
<asp:ListItem>Farmers' Market</asp:ListItem>
<asp:ListItem>Festival</asp:ListItem>
<asp:ListItem>Restaurant Opening</asp:ListItem>
</asp:DropDownList>
</div>
<div id="EventDate" class="EventNavDivs">
<span class="EventTitle">Event Date</span> <br />
<%--<asp:TextBox ID="datepicker" runat="server"></asp:TextBox>--%>
<input id="datepicker" type="text" size="50px" maxlength="12" />
</div>
<div id="EventLocation" class="EventNavDivs">
<span class="EventTitle">Location</span> <br />
<asp:DropDownList ID="ddlEventCity" runat="server">
</asp:DropDownList>
</div>
<div id="EventBtn" class="EventNavBtn">
<br /><asp:Button ID="btnFindEvents" runat="server" Text="Submit"
onclick="btnFindEvents_Click" />
</div>
</div>
</div>
</div>
</asp:Content>
页面后面的代码:
protected void btnFindEvents_Click(object sender, EventArgs e)
{
string EventType = ddlEventType.SelectedValue;
DateTime StartDt = Convert.ToDateTime(Request.Form["datepicker"]);
string City = ddlEventCity.SelectedValue;
BLgetEvents obj = new BLgetEvents();
var EventList = obj.getAllEvents(StartDt);
ListEvents.DataSource = EventList;
ListEvents.DataBind();
}
答案 0 :(得分:2)
将.aspx代码更改为:
<input id="datepicker" type="text" size="50px" maxlength="12" name="DatePickername" />
然后在你的代码隐藏中,执行:
string dt = Request.Form["DatePickername"];