locked
AutoPostBack = true affect the date textbox changes RRS feed

  • Question

  • Dear all,

    I facing the issue for the following
    I have the following component in my webpage:
    <div class="formrows">
                <span class="fieldlable">Report Period:</span>
                <span>
                    <asp:TextBox ID="TextBoxDateStart" ClientIDMode="Static" runat="server" Text="<%# BindItem.DateStart %>" CssClass="textbox" /></span>
                <span>To:</span>
                <span>
                    <asp:TextBox ID="TextBoxDateEnd" ClientIDMode="Static" runat="server" Text="<%# BindItem.DateEnd %>" CssClass="textbox" /></span>
                <asp:RequiredFieldValidator ID="RequiredFieldValidatorStartDate"   Display="None" runat="server" ErrorMessage="Please enter Start Date"  ValidationGroup="validate" ControlToValidate="TextBoxDateStart"></asp:RequiredFieldValidator>    
                <asp:RequiredFieldValidator ID="RequiredFieldValidatorEndDate"   Display="None" runat="server" ErrorMessage="Please enter End Date" Text="" ValidationGroup="validate" ControlToValidate="TextBoxDateEnd"></asp:RequiredFieldValidator>    
                <asp:RegularExpressionValidator ID="RegularExpressionValidatorStartDate" runat="server"   Display="None"  ErrorMessage="Please Start Date in the correct format (mm/dd/yyyy)" ValidationGroup="validate" ControlToValidate="TextBoxDateStart" ValidationExpression="(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])"></asp:RegularExpressionValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidatorEndDate" runat="server"   Display="None"  ErrorMessage="Please End Date in the correct format (mm/dd/yyyy)" ValidationGroup="validate" ControlToValidate="TextBoxDateEnd" ValidationExpression="(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])"></asp:RegularExpressionValidator>
                <asp:CustomValidator runat="server"  EnableClientScript="false" ID="valDateRange"  Display="None" ValidationGroup="validate" ControlToValidate="TextBoxDateStart" onservervalidate="valDateRange_ServerValidate" ErrorMessage="Start Date and End Date must within one month" />
                <asp:CustomValidator runat="server" EnableClientScript="false"  ID="CustomValidatorEndDate"  Display="None" ValidationGroup="validate" ControlToValidate="TextBoxDateEnd" onservervalidate="valEndDateRange_ServerValidate" ErrorMessage="Start Date must earlier than End Date" />
    
            </div>
                
             <div class="formrows">
                <span class="fieldlable">Country:</span>
                <span>
                    <asp:DropDownList ID="ddlCountry" runat="server" DataTextField="Text" DataValueField="Value" AutoPostBack="true" SelectedIndex="<%# BindItem.CountryID %>" SelectMethod="LoadCountry"  OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"></asp:DropDownList>
                </span>
                <asp:RequiredFieldValidator ID="RequiredFieldValidatorCountry" runat="server" ErrorMessage="Country" ControlToValidate="ddlCountry"></asp:RequiredFieldValidator>    
    
            </div>

    For example,

    When I write select the date 2017/02/01 for the date text box and then i select other Country, the date will change to the today date.

    for Backend sourcecode, I already add in

    if (!IsPostBack == true)
    {

    May I know how to solve it when i select the country then the date won't change to current date?



    I&amp;amp;#39;m newbie in enterprise as developer.

    Thursday, March 2, 2017 12:26 AM

All replies

  • http://forums.asp.net/

    It's where you should post.

    Thursday, March 2, 2017 1:57 AM
  • Hi eng teong,

    >>AutoPostBack = true affect the date textbox changes.

    Like your title said, this result is expect.

    Autopostback is the mechanism, by which the page will be posted  back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back.

    which if set to true, will send the request to the server when an event happens in the control.

    >>May I know how to solve it when i select the country then the date won't change to current date?

    You need to set the ViewState property of the date textboxes to true.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 2, 2017 2:35 AM
  • Hi Kristin,

    You mean set the  EnableViewState="true" ??

    Thank you 

    I&amp;amp;#39;m newbie in enterprise as developer.

    Thursday, March 2, 2017 3:44 AM
  • Hi Kristin,

    You mean set the  EnableViewState="true" ??

    Thank you 

    I&amp;amp;#39;m newbie in enterprise as developer.

    @eng teong

    Yes, please try and let me know the result.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 2, 2017 5:17 AM