textbox input changes if dropdown list is visible.

Joseph Hedbon 121 Reputation points

ok. this is the code i have and it does work most of the time and there are no errors either when testing the program.

   Public Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

       'checking for correct age input'
       If Integer.TryParse(TextBox1.Text, age) And age >= 81 Then
           TextBox1.Text = ""
           MsgBox("Please enter an age between 0 and 80")
       ElseIf age < 10 Then

           DropDownList1.Visible = True
       End If

   End Sub

<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 1; left: 75px; top: 70px; position: absolute" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged" autocompolete="off " Wrap="False"></asp:TextBox>

so basically depending on user input determines the visbility of the drop down list other wise it clears the text box and displays an error message. about 50% of the time when i'm changing ages back and forth to trigger the error on the autopostback i get the spinning loading on the EDGE tab and the error message does not show.

any ideas? is there a better way than using the autopostback property?


ASP.NET Web Forms
ASP.NET Web Forms
A part of the ASP.NET web application framework that can be used to create ASP.NET web applications.
650 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,393 questions
0 comments No comments
{count} votes

Accepted answer
  1. XuDong Peng-MSFT 6,776 Reputation points Microsoft Vendor

    Hi @Joseph Hedbon,

    When you use MsgBox it will generate a Message Box on the server. So, if you want to check it you could minimize your Browser and check it in your screen.

    If you want to prompt the user, just use javascript alert in TextChange event will be ok, it will show in browser. Something like this:

    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alertMessage", "alert('Please enter an age between 0 and 80');", True)

    Also, if you want to improve the experience. You could specify it by using UpdatePanel. Cause by default AutoPostBack will refresh the whole page.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
            <asp:DropDownList ID="DropDownList1" runat="server" Visible="False"></asp:DropDownList>

    Best regards,

    Xudong Peng

    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful