【问题标题】:The current context for id does not existid 的当前上下文不存在
【发布时间】:2012-08-23 14:49:47
【问题描述】:

如何从日期选择器中获取会话?

对于我所有的文本框,我使用:

 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>

希望您能提供帮助。

谢谢。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    设置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>
    

    【讨论】:

    • 它正在工作,但我更改代码后我的日期选择器没有弹出。你能告诉我为什么吗?
    • 这是(日期选择器)jQuery UI 小部件吗?
    • 可能标签没有像这样关闭:''
    • 谢谢@AVD!!!!!!你救了我!!!!!你真是个好帮手!谢谢!你不知道,我花了很长时间做这部分!谢谢你。你只是让我的一天!
    猜你喜欢
    • 2015-09-30
    • 2023-03-30
    • 2019-08-05
    • 2020-07-31
    • 2021-01-16
    • 1970-01-01
    • 2018-06-07
    • 2012-10-23
    相关资源
    最近更新 更多