textbox validation - tab key

Antrac1t

Member
Joined
Apr 28, 2014
Messages
13
Programming Experience
Beginner
Hello,
i create validation value from Textbox which is fired by button (fin working), but is there chance to fire it by tab key? All data which will be putted by barcode scanner.

VB.NET:
  Protected Sub ValidateUser_Click(sender As Object, e As EventArgs)


        Dim userId As String
        getMVSHeaderData()
        'Dim constr As String = ConfigurationManager.ConnectionStrings("Data Source =iczfis-report; Initial Catalog = ICZ_LOCAL;Persist Security Info=True;Uid = fisread; password = readfis").ConnectionString


        Using con As New SqlConnection("Data Source =iczfis-report; Initial Catalog = ICZ_LOCAL;Persist Security Info=True;Uid = fisread; password = readfis")
            Using cmd As New SqlCommand("Validate_Sno")
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@Sno", TextBox5.Text)
                cmd.Parameters.AddWithValue("@SubWc", SubWc.Text)
                cmd.Parameters.AddWithValue("@PdLine", PdLine.Text)
                cmd.Parameters.AddWithValue("@User", User.Text)
                cmd.Parameters.AddWithValue("@Po", Po.Text)


                cmd.Connection = con
                con.Open()
                userId = cmd.ExecuteScalar()
                con.Close()
            End Using
            Select Case userId
                Case 0
                    Label1.Text = "Not exist"
                    Exit Select
                Case 1
                    Label1.Text = "First time"
                    Exit Select
                Case 2
                    Label1.Text = "Waiting to finish"
                    Exit Select
                Case 3
                    Label1.Text = "Finished"
                    Exit Select
            End Select
        End Using
    End Sub


HTML:
<body>    <form id="form1" runat="server">        <asp:Button ID="ValidateUser" runat="server" Text="Button" onclick="ValidateUser_Click"  />    <br />
    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>    <br />    <asp:Label ID="Po" runat="server" Text="Label"></asp:Label>    <br />    <asp:Label ID="SubWc" runat="server" Text="Label">RAI-1</asp:Label>    <br />    <asp:Label ID="PdLine" runat="server" Text="Label">CZ0</asp:Label>    <br />    <asp:Label ID="User" runat="server" Text="Label">1300245</asp:Label>    <br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    <br />
    </form></body>


i found this part for validation empty textbox by tab key

VB.NET:
<script type="text/javascript">
    function requird(tabkey) {
        if (tabkey.value == "") {
            alert("Fill TextBox Don't be a Blank ");
            tabkey.focus();
        }
    }
</script>

    <asp:TextBox ID="TextBox5" runat="server" onblur="requird(this)"></asp:TextBox>

but actually dont know how to merge it

thank you
 
Hi, RequiredField validators could not be fired with Tab Key press. You have to use JavaScript for that. You can use onblur event of input field. onblur event occurs when an object loses focus.
So, code with script of onblur function you are referring is right. But instead of alert you can put span tag just after the input field and when user not entered any value in input press tab then onblur function calls and you can show/hide that span tag in that function with your desired text in it.
So, its look like required field validator.
 

Latest posts

Back
Top