嗨,我想在C#中使用Asp.net中的Onkey Press Event [英] Hi i want to Use Onkey Press Event in Asp.net with c#

查看:56
本文介绍了嗨,我想在C#中使用Asp.net中的Onkey Press Event的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
在这里我想用C#在Asp.net的Web应用程序中编写OnkeyPress事件.我知道这在Windows中是可能的,但是如何在用C#的Asp.net中做.
例如:我想计算结果应存储在第三个文本框中的两个数字:

表示Textbox1.text + textbox2.text =结果;

textbox3.text =结果.

第三文本框结果应存储KEYPRESS EVENT.


问候,

Anilkumar.D

Dear Friends,
Here i want to Write OnkeyPress Event in WebApplication in Asp.net with C#.I know it is Possible in Windows But how to do in Asp.net with C#.

Ex:i want to Calcute Two numbers that Result should store in Third Textbox:

Means Textbox1.text+ textbox2.text= result;

textbox3.text= result.

That Third textbox result should store KEYPRESS EVENT.


Regards,

Anilkumar.D

推荐答案

在代码的JavaScript端这更容易. 参见讨论 [
This is easier to in the JavaScript side of the code.
See a discussion[^] and samples using KeyPress.


该第三个文本框结果应存储KEYPRESS事件"

我认为您可以在点击事件中执行此操作.
按键时,您只能允许用户输入数字.
点击第三个文本框,计算结果.

"That Third textbox result should store KEYPRESS EVENT "

I think You can do this on click event.
On key press you can allow user to enter only numbers.
On click on third textbox calculate your result.

<label>First number</label>    <asp:TextBox ID="TextBox1" runat="server" onkeypress="return isNumberKey(event)"></asp:TextBox> <br />

      <label>Second Number</label>  <asp:TextBox ID="TextBox2" runat="server" onkeypress="return isNumberKey(event)" ></asp:TextBox> <br />

      <label>Your result</label>   <asp:TextBox ID="TextBox3" runat="server" ReadOnly="true" onclick="javascript:check()"></asp:TextBox>







<script type="text/javascript">
   function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      
      function check()
      {
    var value = document.getElementById('<%=TextBox1.ClientID%>').value;
    var value1 = document.getElementById('<%=TextBox2.ClientID%>').value;
    if(value!="" && value1!="")
    {

   var sum = parseInt(value)+parseInt(value1);
    document.getElementById('<%=TextBox3.ClientID%>').value = sum;
    }

      }

</script>




希望这行得通!




hope this works !


这篇关于嗨,我想在C#中使用Asp.net中的Onkey Press Event的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆