locked
text box1 and textbox2 = 10 RRS feed

  • Question

  • User1298215938 posted

    Hi, How can i write some code that if textbox1 or textbox2 combined equal to ten it will show the enter button?

    I have listed my code below.

    If Val(textbox1. Text) + Val(textbox2. Text) = 10 Then

    Enter.Visible = "True"
    End If

    Tuesday, August 25, 2020 4:24 PM

Answers

  • User-939850651 posted

    Hi MOHIMRAN,

    Based on your description, I created a simple example. Are you trying something similar?

    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox runat="server" ID="TextBox1" OnTextChanged="TextBox_TextChanged" AutoPostBack="true"></asp:TextBox>
                <hr />
                <asp:TextBox runat="server" ID="TextBox2" OnTextChanged="TextBox_TextChanged" AutoPostBack="true"></asp:TextBox>
                <br />
                <asp:Button runat="server" ID="Enter" Visible="false" Text="Enter"/>
            </div>
        </form>
    </body>
    Protected Sub TextBox_TextChanged(sender As Object, e As EventArgs)
            If Val(TextBox1.Text) + Val(TextBox2.Text) = 10 Then
                Enter.Visible = True
            Else
                Enter.Visible = False
            End If
        End Sub

    Result:

    Your method is feasible. If you encounter any problems, please let me know.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2020 6:32 AM

All replies

  • User409696431 posted

    You should always tell us what happened when you tried your code, and what errors you got.

    Tuesday, August 25, 2020 7:25 PM
  • User-939850651 posted

    Hi MOHIMRAN,

    Based on your description, I created a simple example. Are you trying something similar?

    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox runat="server" ID="TextBox1" OnTextChanged="TextBox_TextChanged" AutoPostBack="true"></asp:TextBox>
                <hr />
                <asp:TextBox runat="server" ID="TextBox2" OnTextChanged="TextBox_TextChanged" AutoPostBack="true"></asp:TextBox>
                <br />
                <asp:Button runat="server" ID="Enter" Visible="false" Text="Enter"/>
            </div>
        </form>
    </body>
    Protected Sub TextBox_TextChanged(sender As Object, e As EventArgs)
            If Val(TextBox1.Text) + Val(TextBox2.Text) = 10 Then
                Enter.Visible = True
            Else
                Enter.Visible = False
            End If
        End Sub

    Result:

    Your method is feasible. If you encounter any problems, please let me know.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2020 6:32 AM