Hi chetan,
Check this sample. now take its reference and correct your code.
HTML
<asp:TextBox ID="txtID" runat="server" /><br /><br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="OnValidate" /><br />
<asp:Label ID="lblID" Text="" runat="server" />
Code
C#
protected void OnValidate(object sender, EventArgs e)
{
int classID;
if (!int.TryParse(txtID.Text, out classID))
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Please Enter Only Numeric Value.')", true);
}
else
{
lblID.Text = "MEASUREMENT CLASS ID : " + Convert.ToString(classID);
}
}
VB.Net
Protected Sub OnValidate(ByVal sender As Object, ByVal e As EventArgs)
Dim classID As Integer
If Not Integer.TryParse(txtID.Text, classID) Then
ClientScript.RegisterStartupScript(Me.[GetType](), "", "alert('Please Enter Only Numeric Value.')", True)
Else
lblID.Text = "MEASUREMENT CLASS ID : " & Convert.ToString(classID)
End If
End Sub
Screenshot