Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

This is easier to in the JavaScript side of the code.
See a discussion[^] and samples using KeyPress.
 
Share this answer
 
v2
Comments
Anil Honey 206 29-Aug-11 2:48am    
Dear Abhinav,

Iam using DevExpress Control TextBox for that TextBox there is no OnkeyPress Property.In Normal asp.net Textbox Having onkeypress Property thats the Problem.SO Iam Unable to write the onkeyPress Event in DevExpress textBox.
"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.

XML
<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>



XML
<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 !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900