TextBox OnTextChanged / PostBack无法正常工作

时间:2014-12-17 13:31:42

标签: c# asp.net

我的问题是,我似乎无法让我的文本框触发OnTextChanged事件。我也检查过,尽管它被设置为true,但它似乎没有做autopostback

基本上,我正在尝试验证文本框中的文本,并根据验证状态启用或禁用按钮。

这是我的代码:

<asp:Panel ID="panelAccessControl" runat="server" Visible="false">
    <asp:Panel ID="panelAddMileageRate" runat="server" BorderWidth="2" >
        <h2>Add Mileage Rate</h2>
        <asp:ScriptManager ID="scriptManagerMileageRate" runat="server" />
        <asp:UpdatePanel ID="updatePanelAddMileageRate" runat="server">
            <ContentTemplate>
                <p>
                    Purpose:
                    <asp:DropDownList ID="ddlAddPurpose" runat="server"
                         AutoPostBack="true" Width="200px"></asp:DropDownList>
                    <br />
                    Country:
                    <asp:DropDownList ID="ddlAddCountry" runat="server"
                         AutoPostBack="true" Width="200px" >
                    </asp:DropDownList>
                    <br />
                    Effective Date:
                    <asp:Calendar ID="calAddEffectiveDate" runat="server"> 
                    </asp:Calendar>
                    <br />
                    Mileage Rate:
                    <asp:TextBox ID="txtAddMileageRate" runat="server"
                        AutoPostBack="true" Width="200px" 
                        CausesValidation="true" 
                        ontextchanged="txtAddMileageRate_TextChanged">
                    </asp:TextBox>
                    <asp:RegularExpressionValidator 
                         ID="validatorAddMileageRate"
                         ControlToValidate="txtAddMileageRate" runat="server" 
                         SetFocusOnError="true"
                         ErrorMessage="Only Numbers allowed" 
                         ValidationExpression="^\d{1,20}(\.\d{0,4})?$">
                    </asp:RegularExpressionValidator>
                </p>
            </ContentTemplate>
        </asp:UpdatePanel>
        <p>
            <asp:Button ID="buttonAddSecurityGroup" runat="server" 
                        Text="Submit" onclick="buttonAddSecurityGroup_Click" />
        </p>
    </asp:Panel>
    <asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
</asp:Panel>

相关文本框为txtAddMileageRate

1 个答案:

答案 0 :(得分:0)

EventName txtAddMileageRate的{​​{1}}属性设为AsyncPostBackTrigger

在更新面板内以及TextChanged

之外添加以下代码
ContentTemplate

其他建议:

您是否尝试过查看属于AjaxControlToolKit的AutoComplete(http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete)控件?它的行为方式与您希望解决方案的行为方式相同。