locked
Automatically check if user exists - is not working completely. RRS feed

  • Question

  • User1216627406 posted

    Greetings experts. Hope all is well as I have not been here for quite sometime now.

    We an app that records users' input into the database.

    Each user can only submit his or her record once.

    To ensure there is no duplicate entry, we require that each user enter his or her unique ID.

    Once that information is provided, using ajax and VB, the system automatically queries the db to determine if the unique ID (if user has already entered record) exists.

    If the unique ID already exists, then the entire form is populated with user's info.

    If that is the first time the user is entering his or her record, the the form is blank.

    This works great.

    The issue is that if a user has already entered his or her record, we have a text that says, this information is already on our database. Modify the existing record or exit the system. There is an image called NotAvailable.jpg that is supposed to display along this message.

    This image along with the message are not displaying.

    Similarly, if no record exists for this user, again, there is a message that says, please enter this user's record along with an image called icon_Available.gif.

    Again, this image along with message is not displaying.

    Does anyone have any idea what's wrong?

    Here is some relevant code.

    Your assistance is greatly appreciated in advance.

    'VB
        Protected Sub txtVoterReg_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
            If Not String.IsNullOrEmpty(txtVoterReg.Text) Then
                Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
                con.Open()
                Dim cmd As SqlCommand = New SqlCommand("select * from tableOne where registration=@voterid", con)
                cmd.Parameters.AddWithValue("@voterid", txtVoterReg.Text)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
    
                If dr.HasRows Then
                    checkusername.Visible = True
                    imgstatus.ImageUrl = "Images/NotAvailable.jpg"
                    lblStatus.Text = "User is already on the database. Modify record if needed"
                    fillRecords()
                    System.Threading.Thread.Sleep(2000)
    
                Else
                    checkusername.Visible = True
                    imgstatus.ImageUrl = "Images/Icon_Available.gif"
                    lblStatus.Text = "Please proceed to add this user to the database"
                    System.Threading.Thread.Sleep(2000)
                End If
            Else
                checkusername.Visible = False
            End If
        End Sub
        
    'JS
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <script type="text/javascript">
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
            function BeginRequestHandler(sender, args) {
                var state = document.getElementById('loadingdiv').style.display;
                if (state == 'block') {
                    document.getElementById('loadingdiv').style.display = 'none';
                } else {
                    document.getElementById('loadingdiv').style.display = 'block';
                }
                args.get_postBackElement().disabled = true;
            }
       </script>
       
     'HTML
         <asp:UpdatePanel ID="PnlUsrDetails" runat="server">
            <ContentTemplate>
        <div>
          <asp:Panel ID="PnlVerify" runat="server" Width="800px" BorderWidth="2"> 
               <div>
                <table style="width:800px;border:0;">
                 <tr>
                     <td>
                         <div class="input text">
                             <label id="lblVoterID">
                                 <span style="font-weight: bold; font-size: 16px; color: #000000;">Enter voter registration # to begin</span><span
                                     style="color: #ff0000">*</span></label>
                             <asp:TextBox ID="txtVoterReg" maxlength="10" placeholder="Voter Registration ID..." Style="width: 150px;" class="form-control"
                                 runat="server" AutoPostBack="true" OnTextChanged="txtVoterReg_TextChanged"></asp:TextBox>
                             <br />
                         </div>
                     </td>
                     <td>
                        <div class="bd-callout bd-callout-danger" id="dprocessed" style="width:70%;white-space:nowrap;" runat="server" visible="false">
                         <div id="checkusername" runat="server" visible="false">
                             <asp:Label ID="Label1" runat="server"></asp:Label>
                             <asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px" />
                         </div>
                       </div>
                       <div class="waitingdiv" id="loadingdiv" style="display:none;margin-left:5.3em">
                        <img src="images/ajax-loader.gif" alt="Loading" />Please wait...
                       </div>
                      </td>
                    </tr>
                   </table>
                   </div>
                </asp:Panel> 
               </div> 
               ...
               ...
           </ContentTemplate>
        </asp:UpdatePanel>

    Saturday, September 19, 2020 1:43 AM

Answers

  • User-939850651 posted

    Hi simflex,

    According to your description, I tested the code you provided.

    The cause of the problem is this:

    <div class="bd-callout bd-callout-danger" id="dprocessed" style="width:70%;white-space:nowrap;" runat="server" visible="false">
                         <div id="checkusername" runat="server" visible="false">
                             <asp:Label ID="Label1" runat="server"></asp:Label>
                             <asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px" />
                         </div>
                       </div>

    You set the visible attribute to false  in the outer div of checkusername, it will not be displayed, and you have not modified its value in the event, which caused the problem. Please check it.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2020 3:52 AM

All replies

  • User-939850651 posted

    Hi simflex,

    According to your description, I tested the code you provided.

    The cause of the problem is this:

    <div class="bd-callout bd-callout-danger" id="dprocessed" style="width:70%;white-space:nowrap;" runat="server" visible="false">
                         <div id="checkusername" runat="server" visible="false">
                             <asp:Label ID="Label1" runat="server"></asp:Label>
                             <asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px" />
                         </div>
                       </div>

    You set the visible attribute to false  in the outer div of checkusername, it will not be displayed, and you have not modified its value in the event, which caused the problem. Please check it.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2020 3:52 AM
  • User1216627406 posted

    Thanks for catching that.

    Monday, September 21, 2020 1:54 PM