I have a textbox and a homemade datecalendar. Pressing a date div (class .available) in a calendar triggers jquery to enter the date in the textbox, see code:
<asp:TextBox id="hidOutboundSelectedDate" ClientIDMode="Static" runat="server" />
$(".available").click(function () {
var selected = $(this).text();
$("#hidOutboundSelectedDate").val(selected);
});
I press the search button and eventually enter the following code behind method:
public string GetSelected()
{
var test1 = Request.Form[hidOutboundSelectedDate.UniqueID];
var test2 = hidOutboundSelectedDate.Text;
var test3 = FindControl("hidOutboundSelectedDate");
// some extra code goes here
}
At this moment all of these 3 versions (test3 will be debugged to check .Text) show the same value, the one i picked in my calendar.
Now to the issue:
I “go back” to choose a new date from my calendar, the textbox is empty like it was in the begining. I select a date, the jquery sets the value to the new date. If i go to the Chrome browser console and check what the value is, i get the correct value in return.
I eventually reach the “GetSelected()” method and my 3 test versions gives the following result:
test1 = null
test2 = old value
test3 = old value
What am I doing wrong?
Can you confirm which stage of the page lifecycle is the GetSelected() method called? Trying to read the value before the posted data is loaded will result in the above result..