Reputation: 49
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;
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.
Thanks.
Upvotes: 2
Views: 2430
Reputation: 94635
Set runat=server
attribute to convert html tag to Html server control.
<input type="text" runat="server" id="datepicker">
and use value
attribute because it is now ASP.NET Web Server control.
Session["date"] = datepicker.Value;
Edit: 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>
Upvotes: 2