gpt4 book ai didi

c# - id 的当前上下文不存在

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:37 25 4
gpt4 key购买 nike

如何从日期选择器中获取一个 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 服务器控件。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com