使用 Javascript 调用 TextChanged 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20422119/
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
Calling TextChanged Event using Javascript
提问by The Hungry Dictator
I am working on a project in which i have used autocomplete extender
with textbox. And on textxhanged event of that textbox i am populating two dropdown which were initially empty. Now the thing is i have two panel. I am copying data from one panel to another. All the attributes of both panels
are same. Now the thing is that i am having two radio button one is for copying data from panel one and other is for new data insert. Now if i choose copy option then it is copying all the values but at that those two dropdown
stay empty. And i am doing it by using javascript. Please suggest me or guide me to solve this problem. Is it possible to call textchanged
event of textbox using javascript??
我正在开发一个autocomplete extender
与文本框一起使用的项目。在该文本框的 textxhanged 事件中,我填充了两个最初为空的下拉列表。现在的事情是我有两个面板。我正在将数据从一个面板复制到另一个面板。两者的所有属性panels
都相同。现在问题是我有两个单选按钮,一个用于从面板一复制数据,另一个用于新数据插入。现在,如果我选择复制选项,那么它会复制所有值,但那两个值dropdown
保持为空。我是通过使用 javascript 来实现的。请建议我或指导我解决这个问题。是否可以textchanged
使用javascript调用文本框的事件?
Note: I am populating dropdowns and autocompleteextender using database.
注意:我正在使用数据库填充下拉菜单和 autocompleteextender。
回答by akta kalariya
You can use onchange event of textbox in javascript.
您可以在 javascript 中使用文本框的 onchange 事件。
回答by Ali
Solution:
解决方案:
Try this,
试试这个,
<script type="text/javascript">
window.onload = xyz;
function xyz() {
document.getElementById('<%= button1.ClientID %>').click();
}
<script>
<asp:TextBox ID="textbox1" runat="server" ontextchanged="textbox1_TextChanged"></asp:TextBox>
<asp:Button ID="button1" runat="server" style=" display:none;" onclick="button1_Click" />
CodeBehind:
代码隐藏:
protected void button1_Click(object sender, EventArgs e)
{
textbox1_TextChanged(null, null)
}
protected void textbox1_TextChanged(object sender, EventArgs e)
{
//your code here
}
回答by Ravi
you can you __doPostBack javascript function from asp.net with the name of text box for which you want to raise this event.
您可以使用 __doPostBack javascript 函数从 asp.net 使用要为其引发此事件的文本框的名称。