我的网页中有以下组件:
<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>
例如,
当我写日期文本框选择日期2017/02/01然后我选择其他国家时,日期将更改为今天日期。
对于后端源代码,我已添加:
if (!IsPostBack == true)
{
...
但它根本没有效果。
我可以知道如何解决它吗?