Use this code , it works... i wrote and tested it.
private void button1_Click(object sender, EventArgs e)
{
int expectedResultFormat;
string ExpPer = txtTotalExpPer.Text;
bool myResult = Int32.TryParse(ExpPer, out expectedResultFormat);
if (myResult == true)
{
int totalexp = Int32.Parse(txtTotalExpPer.Text);
}
else
{
MessageBox.Show("Please only numbers are allowed !!! ");
}
}