本文介绍了嗨,我想在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

推荐答案


<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 10:42