Click here to Skip to main content
11,437,397 members (34,338 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 28-Aug-11 21:30pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is easier to in the JavaScript side of the code.
See a discussion[^] and samples using KeyPress.
  Permalink  
v2
Comments
archanakumari at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

"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 !
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 29 Aug 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100