Hi sambath,
Please refer below sample.
HTML
<script type="text/javascript">
function Check() {
var message = '<%=Session["otp"] %>';
var otp = document.getElementById('txtOTP').value;
var countdigit = otp.length;
if (countdigit == 4) {
if (otp == message) {
document.getElementById('lblMessage').innerHTML = "Correct OTP";
}
else {
document.getElementById('lblMessage').innerHTML = "Incorrect OTP";
}
}
else {
document.getElementById('lblMessage').innerHTML = "";
}
return false;
}
</script>
<div>
Enter OTP:
<asp:TextBox ID="txtOTP" class="otp" runat="server" MaxLength="4" TextMode="Password"
onkeyup="Check();" />
<br />
<asp:Label ID="lblMessage" runat="server" />
</div>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Session["Otp"] = "1234";
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Session("Otp") = "1234"
End If
End Sub
Screenshot