如何在asp.net文本框中使用onchange事件 [英] How to Use onchange event in asp.net textbox
问题描述
Hello Experts,
我有一个表单,它有两个文本框。现在,在第一个文本框中输入一些ID时,我需要通过使用文本框的onchange事件获取存储在sql server数据库中的特定ID的相关名称。
我给第一个文本框Onchange =change(this)..
头脑中我写了这个函数
< script type =text / Javascript> change(){< br $>
}
< / script>
如何使用getElementbyId并将名称提取到第二个文本框中
Hello Experts,
I have a form and it has two textboxes. Now on entering some ID in the first textbox, i need to get the relevant name of that particular ID which is stored in the sql server database by using onchange event for the textbox.
For the first textbox i have given Onchange= "change(this)"..
And in the head i have written the function
<script type="text/Javascript> change(){
}
</script>
How to use the getElementbyId and fetch name into the second textbox
推荐答案
您好,
如果要求不是您的要求需要在客户端进行处理,
您可以使用第一个文本框的OnTextChanged事件来访问C#代码中的sql server数据库,并使用适当的值填充第二个文本框。
< asp:textbox id =txtTestrunat =server ontextchanged =txtTest_TextChangeautopostback =truexmlns:asp =#unknown>
C#代码
protected void txtTest_TextChange(object sender,EventArgs e)
{
//在这里做你的东西
}
Hi,
If the requirement is not such that you need to do the processing at the client side,
you can use the "OnTextChanged" event of the first text box to access the sql server database in your C# code and populate the second textbox with the appropriate values.
<asp:textbox id="txtTest" runat="server" ontextchanged="txtTest_TextChange" autopostback="true" xmlns:asp="#unknown">
C# code
protected void txtTest_TextChange(object sender, EventArgs e)
{
//Do your stuff here
}
这篇关于如何在asp.net文本框中使用onchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!