Я поддерживаю приложение 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>
The 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>
В случае, если это связано с панелью обновлений, я не очень знаком с веб-формами.