id的当前背景下不存在 [英] The current context for id does not exist

查看:113
本文介绍了id的当前背景下不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能保存从日期选择器会话?

How can I get hold a session from date picker?

有关我所有的文本框,我拿着它使用:

For all my textbox, I hold it using :

 Session["location"] = DropDownList1.SelectedItem.Text;
 Session["time"] = DropDownList2.SelectedItem.Text;
 Session["day"] = DropDownList3.SelectedItem.Text;  
 Session["IsChauffeurUsed"] = DropDownList4.SelectedItem.Text;

但我的文本框中日期选择器,当我写了code

But for my text box date picker, when I write the code

 Session["date"] = datepicker.Text;

它给了我一个错误,在目前的情况下不存在。
日期选择器的文本框是:

It gives me an error, the current context does not exist. The date picker text box is :

<div class="demo"><p>Date: <input type="text" id="datepicker"></p></div>

希望能对你有所帮助。

Hope you can help.

感谢。

推荐答案

设置 RUNAT =服务器属性html标记转换为HTML服务器控件。

Set runat=server attribute to convert html tag to Html server control.

<input type="text" runat="server" id="datepicker">

和使用属性,因为它现在是ASP.NET Web服务器控件。

and use value attribute because it is now ASP.NET Web Server control.

Session["date"] = datepicker.Value;

编辑:这工作完全在我的身边。

This works perfectly on my side.

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

这篇关于id的当前背景下不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆