代码之家  ›  专栏  ›  技术社区  ›  Nickso

不触发webforms上的按键

  •  1
  • Nickso  · 技术社区  · 6 年前

    我正在维护一个webforms应用程序。

    有一个 .ascx 在这里我有下面的脚本 .ascx公司 在登记之后:

    <script language="javascript" type="text/javascript">
    
        $(document).ready(function () {
            $('#<%=txtMotivoRechazo.ClientID%>').keypress(function () {
                    var cantCaracteres = this.val().length;
    
                    if (cantCaracteres >= 250) {
                        $('#<%=lblCuentaCaracteres.ClientID%>').css('color', 'red');
                    }
                    else {
                        $('#<%=lblCuentaCaracteres.ClientID%>').css('color', 'black');
                    }
    
                    $('#<%=lblCuentaCaracteres.ClientID%>').text(cantCaracteres);
            });
        });
    </script>
    

    这个 asp:label lblCuentaCaracteres 以及 asp:textbox txtMotivoRechazo 在一个 UpdatePanel 在一个 ContentTemplate

    简而言之,这是ASCx:

        <script language="javascript" type="text/javascript">
    
            $(document).ready(function () {
                $('#<%=txtMotivoRechazo.ClientID%>').keypress(function () {
                        var cantCaracteres = this.val().length;
    
                        if (cantCaracteres >= 250) {
                            $('#<%=lblCuentaCaracteres.ClientID%>').css('color', 'red');
                        }
                        else {
                            $('#<%=lblCuentaCaracteres.ClientID%>').css('color', 'black');
                        }
    
                        $('#<%=lblCuentaCaracteres.ClientID%>').text(cantCaracteres);
                });
            });
        </script>
    
     <asp:UpdatePanel ID="upMensaje" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
                    <asp:Panel ID="pnlMotivoRechazo" runat="server" Height="100%" ScrollBars="Auto" TabIndex="-1" class="tcFilterContent">
                        <div id="MotivoRechazo" >
                            <h2>Motivo del Rechazo</h2>
                            <div id="MensajeEmail">
                                <asp:Label ID="lblMensajeNoSupera" runat="server" CssClass="MensajeCaracteres"></asp:Label>
                                <asp:Label ID="lblCuentaCaracteres" runat="server" CssClass="CuentaCaracteres"></asp:Label>
                                <asp:Label ID="lblMensajeCuentaCaracteres" runat="server" CssClass="CuentaCaracteres"></asp:Label>
    
                            </div>
                            <asp:TextBox ID="txtMotivoRechazo" runat="server" TextMode="MultiLine" Rows="5" Width="100%" MaxLength="250" CssClass="txt3c3"/>
                        </div>
                        <div class="tcButtonList" id="divBotonesRechazo">
                            <asp:Button ID="btnRechazarPreAceptar" runat="server" Text="Aceptar" OnClick="btnRechazarPreAceptar_Click" class="button"/>
                        </div>
                    </asp:Panel>
       </ContentTemplate>
     </asp:UpdatePanel>
    

    但是,当我在文本框中写的东西没有触发按键时,我也尝试了keydown或keyup。 我试着用:

    <Triggers>
        <asp:PostBackTrigger ControlID="txtMotivoRechazo" />
    </Triggers>
    

    如果是与更新面板相关的,我不太熟悉webforms。

    0 回复  |  直到 6 年前