vb.net textChanged 事件不会触发,我有 autopostback=true
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16957951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
textChanged event doesn′t fire and i have autopostback=true
提问by Mikelon85
I have a textbox event declarated but it doesn′t fire. I have seen in SO other answers but all of them say that autopostback property has been true and i have it
我声明了一个文本框事件,但它没有触发。我在 SO 其他答案中看到过,但他们都说 autopostback 属性是真的,我有
my aspx
我的aspx
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<asp:TextBox runat="server" ID="txtDia" Width="120px" Height="20px"
AutoPostBack="True" CssClass="textbox" OnTextChanged="txtDia_TextChanged"/>
<Juice:Datepicker ID="Datepicker2" runat="server" TargetControlID="txtDia"
DateFormat="dd/mm/yy"
MonthNames="Enero,Febrero,Marzo,Abril,Mayo,Junio,Julio,Agosto,Septiembre,Octubre,Noviembre,Diciembre"
MonthNamesShort="Ene,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic,"
AutoPostBack="True" /></td>
and my aspx.vb
和我的 aspx.vb
Protected Sub txtDia_TextChanged(sender As Object, e As System.EventArgs) Handles txtDia.TextChanged
CargarDatos()
End Sub
回答by Viktor S.
You should define your textbox like this (see OnTextChanged="txtDia_TextChanged"being added):
你应该像这样定义你的文本框(见OnTextChanged="txtDia_TextChanged"被添加):
<asp:TextBox OnTextChanged="txtDia_TextChanged"
runat="server" ID="txtDia" Width="120px" Height="20px"
AutoPostBack="True" CssClass="textbox"/>
And remember that this event will rise onblur (focus removed from that textbox) only.
请记住,此事件只会在模糊(焦点从该文本框中移除)上升。
回答by Pawan
In your aspx you should write
在你的 aspx 你应该写
<asp:TextBox runat="server" ID="txtDia" Width="120px" Height="20px"
AutoPostBack="True" CssClass="textbox" OnTextChanged="txtDia_TextChanged"/>
回答by Tim Schmelter
The event is not triggered if you overwrite the text in codebehind. So for example if you databind the control where the TextBoxsits in.
如果您覆盖代码隐藏中的文本,则不会触发该事件。因此,例如,如果您将控件所在的位置进行数据绑定TextBox。
You should so that only If Not IsPostBack:
你应该这样做If Not IsPostBack:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostback)
{
DataBindAllControls(); // including your textbox
}
}
Edit: Sorry, here VB.NET:
编辑:对不起,这里是 VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
DataBindAllControls() ' including your textbox
Else
End Sub
回答by Jay Zelos
What FAngel said is correct.
FAngel 说的是正确的。
I've had the same issue when validating dates and using jquery datepicker. I used the below to fire the validation routines after the box had been populated. So technically they fired twice, once after the textbox had lost focus to the datepicker, then again when my code fired after the datepicker had populated the textbox. It would have been better to disable the onblur event and call directly from the below, but wasn't possible in my project.
我在验证日期和使用 jquery datepicker 时遇到了同样的问题。在填充框后,我使用以下内容来触发验证例程。所以从技术上讲,他们触发了两次,一次是在文本框失去对日期选择器的焦点之后,然后在我的代码在日期选择器填充文本框之后触发。最好禁用 onblur 事件并直接从下面调用,但在我的项目中是不可能的。
$('.datePicker').each(function () {
$(this).datepicker({
onSelect: function () {
$(this).trigger('blur');
}
});
});
You can use a variation on this by disabling the auto-postback and manually triggering it via the onSelect event.
您可以通过禁用自动回发并通过 onSelect 事件手动触发它来使用此变体。
回答by Dan
You need to specify the method to be called when the event is fired like so:
您需要指定在触发事件时要调用的方法,如下所示:
<asp:TextBox runat="server" ID="txtDia" Width="120px" Height="20px" OnTextChanged="txtDia_TextChanged" AutoPostBack="True" CssClass="textbox"/>
Note:
笔记:
OnTextChanged="txtDia_TextChanged"

