如何通过日期选择器举行 session ?
对于我所有的文本框,我使用:
Session["location"] = DropDownList1.SelectedItem.Text;
Session["time"] = DropDownList2.SelectedItem.Text;
Session["day"] = DropDownList3.SelectedItem.Text;
Session["IsChauffeurUsed"] = DropDownList4.SelectedItem.Text;
但是对于我的文本框日期选择器,当我编写代码时
Session["date"] = datepicker.Text;
它给了我一个错误,当前上下文不存在。 日期选择器文本框是:
<div class="demo"><p>Date: <input type="text" id="datepicker"></p></div>
希望能帮到你。
谢谢。
最佳答案
设置runat=server
属性将html标签转换为Html服务器控件。
<input type="text" runat="server" id="datepicker">
并使用value
属性,因为它现在是 ASP.NET Web Server 控件。
Session["date"] = datepicker.Value;
编辑:这对我来说非常有效。
<head runat="server">
<title></title>
<link rel="Stylesheet" type="text/css" href="http://code.jquery.com/ui/jquery-ui-git.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function () {
$("#datePicker").datepicker();
$("#<%=TextBox1.ClientID %>").datepicker();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="datePicker" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
关于c# - id 的当前上下文不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12170388/