I have an application page (in a SharePoint application, if that is relevant) with a JQuery datepicker widget registered:
<script type="text/javascript">
// Create JQuery calendar
$(document).ready(function () {
$('#<%=TextBoxDato.ClientID %>').datepicker({ altField: "#<%=TextBoxDato.ClientID %>",
altFormat: 'dd/mm/yy'
});
$.datepicker.setDefaults($.datepicker.regional['no']);
});
</script>
<asp:TextBox ID="TextBoxDato" runat="server" />
<asp:Button ID="ButtonSubmit" runat="server" text="Do it" />
In the code-behind, on page load I add a small client-side script to validate the filename and then populate the text box with today’s date:
// Add client-side script to check for existing file names
ButtonSubmit.Attributes.Add("onclick", "javascript:return checkFile()");
// Fill date box with today's date
DateTime now = DateTime.Now;
…then, in the event handler for a click to ButtonSubmit, I try to read out the value that the user selected:
DateTime now = DateTime.Parse(TextBoxDato.Text, new CultureInfo("fr-FR"));
My problem is that when clicking ButtonSubmit, the date that the user selected seems to be ignored in the code-behind – the value of ‘now’ is always today’s date. When running a debugger, the checkFilename() JavaScript method is able to access the picked date, but the code-behind is not. Does anyone see what I’m doing wrong?
You say
You are settings the
TextBoxvalue with the current date on page load. Put in some extra code on thePage_LoadmethodVB
c#
Otherwise everytime you click the button, the value will reset to the page load value