How to write Events in Asp .Net
-
how to write events in asp.net like in windows forms leave events,key press event.
-
how to write events in asp.net like in windows forms leave events,key press event.
-
how to write events in asp.net like in windows forms leave events,key press event.
Keypress event is used when you want to write the code based on the keys having ASCII value. The second argument e for keypress event is of type keypresseventargs and it has a property keychar that contains the character pressed by the user on the keyboard and this property is used to write the codein keypress event. can you try this for keypress event: private void KeypressEvent_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case 'A': case 'a': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) + Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'S': case 's': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) - Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'M': case 'm': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) * Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'D': case 'd': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) / Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'C': case 'c': TxtNum1.Clear(); TxtNum2.Clear(); TxtResult.Clear(); TxtNum1.Focus(); e.Handled = true; break; case 'X': case 'x': this.Close(); break; } }
-
Keypress event is used when you want to write the code based on the keys having ASCII value. The second argument e for keypress event is of type keypresseventargs and it has a property keychar that contains the character pressed by the user on the keyboard and this property is used to write the codein keypress event. can you try this for keypress event: private void KeypressEvent_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case 'A': case 'a': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) + Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'S': case 's': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) - Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'M': case 'm': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) * Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'D': case 'd': TxtResult.Text = (Convert.ToInt32(TxtNum1.Text) / Convert.ToInt32(TxtNum2.Text)).ToString(); e.Handled = true; break; case 'C': case 'c': TxtNum1.Clear(); TxtNum2.Clear(); TxtResult.Clear(); TxtNum1.Focus(); e.Handled = true; break; case 'X': case 'x': this.Close(); break; } }
-
how to write events in asp.net like in windows forms leave events,key press event.
-
For most events you want to add JavaScript client side event handlers. You can write server side event handlers on anything with runat=server but these cause the page to be posted back and reloaded, which is annoying to work with.
Thank u BobJanova.,