How to use Button control on trigger action in ASP.NET

This article shows you how to use asp button control on trigger action to specify an UpdatePanel to refresh its contents in ASP.NET.
  • 2170

This article shows you how to use asp buttons on trigger action to specify an UpdatePanel to refresh its contents. In the following example we use to enter two numbers in the textbox and click one of the button specified for their addition, subtraction, multiplication and division to show the result.

Example
 
<%@ Page Language="VB" %>
<script runat="server">
  Sub btAdd_Click(Sender As Object, E As EventArgs)
     lblMessage.Text = "The addition of both numbers is: " & CInt(tbNumber1.Text) + CInt(tbNumber2.Text)
  End Sub 
  Sub btSubtract_Click(Sender As Object, E As EventArgs)
     lblMessage.Text = "The subtraction of both numbers is: " & CInt(tbNumber1.Text) - CInt(tbNumber2.Text)
  Sub btMultiply_Click(Sender As Object, E As EventArgs)
     lblMessage.Text = "The multiplication of both numbers is: " & CInt(tbNumber1.Text) * CInt(tbNumber2.Text)
  End Sub
  Sub btDivide_Click(Sender As Object, E As EventArgs)
     lblMessage.Text = "The division of both numbers is: " & CInt(tbNumber1.Text) / CInt(tbNumber2.Text)  End Sub
</script>
<
HTML>
<
HEAD>
 
 <style type="text/css">
     #Form1
     {
       height: 162px;
     }
   </style>
</HEAD>
<
BODY>
<
form id="Form1" runat="server">
Enter First Number&nbsp; <asp:textbox id="tbNumber1" runat=server/>
<br />
<br>
Enter Second Number&nbsp; <asp:textbox id="tbNumber2" runat=server/>
<br />
<br />
<asp:button id="btAdd" Text="   +   " OnClick="btAdd_Click" runat=server/>
<asp:button id="btSubtract" Text="   -   " OnClick="btSubtract_Click" runat=server/>
<asp:button id="btMultiply" Text="   *   " OnClick="btMultiply_Click" runat=server/>
<asp:button id="btDivide" Text="   /   " OnClick="btDivide_Click" runat=server/>
<br />
<br />
<asp:label id="lblMessage" font-size="14pt" runat=server/>
</form></BODY>
</HTML>

Output Window

button.gif

 

I hope this will help you.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.