1

This is the code for my Textbox (DepartureDateTB):

<asp:TextBox ID="DepartureDateTB"
             runat="server"
             CssClass="DepartureDateTB"
             ClientIDMode="Static"
             ontextchanged="DepartureDateTB_TextChanged"
             EnabledViewState="False"
             AutoPostBack="True">
</asp:TextBox>
<asp:CompareValidator ID="CompareValidator1"
                      runat="server"
                      ControlToCompare="ArrivalDateTextBox"
                      ControlToValidate="DepartureDateTB"
                      ErrorMessage="*Departure to be greater"
                      ForeColor="Red"
                      Operator="GreaterThan">
</asp:CompareValidator>

JQuery for Date Picker:

$(function () {
            $("[id$='DepartureDateTB']").datepicker({ minDate: 0, maxDate: "+30D" });
            $("[id$='DepartureDateTB']").datepicker("option", "dateFormat", "dd/mm/yy");

    });
</script>  

On Page load, I am assigning a value to the textbox from database.

Then when the user changes it, there's a postback but the changed value is not retained.

Even when I tried assigning a Session variable to it and then equate it, all I get is an empty textbox.

Session["DepDateTB"] = (Request.Form[DepartureDateTB.UniqueID]).ToString();
                DepartureDateTB.Text = Session["DepDateTB"].ToString();

And when I position a break point and run it, when I hover over the Textbox the value of it is the changed date but the textbox in the front end is again empty.

5
  • You must have not included !IsPostBack in your Page_Load event. Included one and inside it add Initial data. Commented Jan 14, 2016 at 6:54
  • My initial data is getting added. It's only the changed data that is not appearing on postback. Commented Jan 14, 2016 at 6:58
  • Change EnabledViewState="True", if that helps ? BTW why it is false ? Commented Jan 14, 2016 at 7:12
  • @Dot_NETPro Even when it is true, the issue persists. Commented Jan 14, 2016 at 7:14
  • Please post all your Page_Load code Commented Jan 14, 2016 at 7:20

1 Answer 1

1

The reason the date wasn't getting displayed was due to the following line in the jQuery code:

$("[id$='DepartureDateTB']").datepicker("option", "dateFormat", "dd/mm/yy");

Once the date format option was removed it worked fine.

I resorted to changing the date format in my c# code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.