从 javascript 强制服务器 TextChanged 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12103740/
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
Force server TextChanged event from javascript
提问by K. Weber
I've got a asp:TextBox that is populated from a javascript function, but when this happens the server side TextChanged event is not fired, only when I change the text with my keyboard.
我有一个由 javascript 函数填充的 asp:TextBox,但是当发生这种情况时,不会触发服务器端 TextChanged 事件,只有当我使用键盘更改文本时。
Is there a solution for this? Why is client/server integration so painful in asp.net?
有解决方案吗?为什么在asp.net 中客户端/服务器集成如此痛苦?
(AutoPostBack is set to true)
(AutoPostBack 设置为 true)
Thank you
谢谢
回答by Pranay Rana
Way 1:
方式一:
function DoPostBack()
{
__doPostBack("txt_sssn_dt", "TextChanged");
}
Calling ASP.NET server-side events using JavaScript
使用 JavaScript 调用 ASP.NET 服务器端事件
Way 2:
方式二:
Calling Server Side function from Client Side Script
Way 3:
方式3:
one of the way to set focus lost like this
设置焦点的方法之一像这样丢失了
function texboxchange() {
var txtBox = document.getElementById('<%= TextBox4.ClientID %>');
var count = txtBox.value.length;
if (count == 2)
{
document.getElementById('<%= TextBox12.ClientID %>').focus();
return true; // this will call textbox changed event.
}
}
回答by Mayank Pathak
you can force it firing using __doPostBack('footxtBox','TextChanged');
in your JS
function.
你可以__doPostBack('footxtBox','TextChanged');
在你的JS
函数中强制它触发 。