Hi all,

I'm trying to write what looks like a pretty simple user control for selecting a range of dates.

I'm using two CalendarExtender AJAX ToolKit things, which are each linked to a TextBox control. There are other buttons to shift the dates around one month or week at a time, and they work fine using session variables to retain selected date values across postbacks. It's the selecting arbitrary dates with the CalendarExtender that is failing.

I'm using the OnClientDateSelectionChanged attribute to run a Javascript function that writes the selected value to a hidden field, then writes that to a session variable:
Code:
function updateTo()
{
    var dateStr = document.getElementById( '<%=txtTo.ClientID %>' ).value;
    document.getElementById( '<%=hiddenTo.ClientID %>' ).value = dateStr;
    <%
        Session["userDateTo"] = hiddenTo.Value;
    %>
}
The problem is that it's always one page reload behind. The first time the Update button is pressed, the new date values are replaced in the textbox with the old values. The second time it's pressed, the old values are finally replaced with the new values.

By stepping through the code with breakpoints, I've found that on the first postback the session variables created by the Javascript exist (in that the keys exist) but the values are an empty string. On the second postback they then get their values. I really don't understand how/why this is happening the way it is.

I can provide necessary code snippets if required.

Cheers,
D.