如何在asp.net中使用Keypress事件 [英] how to use Keypress Event in asp.net
本文介绍了如何在asp.net中使用Keypress事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Web应用程序中的textbox keypress事件上添加两个文本框值?
how to add two textbox value on textbox keypress event in web application?
推荐答案
要解决您的问题,请按照以下步骤操作。
第1步:创建java脚本函数
函数txtOnkeypress()
{
//在这里应用你的逻辑..
}
例如:
To resolve your problem follow below step.
step 1: Create java script function
function txtOnkeypress()
{
// apply your logic here..
}
For example:
<script type="text/javascript">
function txtOnKeyPress(txt1)
{
if (txt1 != 'undefined')
{
txt2 = document.getElementById('<%=TextBox2.ClientId %>');
txt2.value = txt1.value;
}
}
</script>
第2步:在文本框按键事件上调用javascript函数。
onkeyPress = txtOnkeypress()
例如:
step 2: call javascript function on textbox key press event.
onkeyPress = txtOnkeypress()
For example:
<asp:TextBox ID="texbox1" runat="server" onkeydown="txtOnKeyPress(this);" ></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
谢谢
Vipul patel
Thanks
Vipul patel
protected void textbox1_KeyPress(Object sender,KeyPressEventArgs e)
{
if(e.KeyChar==(char)Keys.Tab)
{
Keybox4.Focus();
}
}
Addionally MultiLine属性设置为true,AcceptsTab也设置为true 。
Addionally MultiLine property set to true, and AcceptsTab also set to true.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
这篇关于如何在asp.net中使用Keypress事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文