Hi guys!
i've got this asp.net page that calculate 2 integer and add both of them to get the new value and it is working. Now i want to add in a validation that check for the 1st textbox to see if it is empty or not. If it is empty then it will pop out a msg saying that it is empty. I think i did it correctly buy it seems to show an error when i try to run it. I will attach the code here and please have a look.
can any 1 help me solve this problem? I'm still learning asp.net. THe validation check i did is inCode:<%@ Page Language="VB" %> <html> <script language="vb" runat="server"> Sub SubmitBtn_Click(Sender as object, E as EventArgs) if text1.text = "" then msgbox("empty") else result.Text = val(Text1.text) + val(Text2.text) end if End Sub </script> <head> <title>Calculation</title> <link rel="stylesheet"href="intro.css"> </head> <body> <center> <form action="calulate.aspx" method="post" runat=server> <h3> Number 1: <asp:TextBox id="text1" runat="server"/> Number 2: <asp:TextBox id="text2" runat="server"/> </h3> <p> <b>Answer Is:</b> <asp:TextBox id="result" runat="server"/> </p> <p> <asp:Button text="Calculate" onClick="SubmitBtn_Click" runat="server"/> </p> </form> </center> </body> </html>
with the if else statement. Please have a look and help me. Thanks.Code:Sub SubmitBtn_Click(Sender as object, E as EventArgs) if text1.text = "" then msgbox("empty") else result.Text = val(Text1.text) + val(Text2.text) end if End Sub




Reply With Quote