First you need to check that the querystring parameter is not null. Then you need to check that the value is actually an integer before trying to convert it. For this you can use the method Int32.TryParse
. If the value is a convertible to an int, it will do the conversion for you at the same time.
For example:
if (Request.QueryString["RegNo"] != null) {
int num = 0;
bool parseResult = Int32.TryParse(Request.QueryString["RegNo"].ToString(), out num);
if (parseResult == true) {
//valid number, so continue
if (!IsPostBack)
{
BindTextBoxvalues();
}
}
else {
//do something suitable here like display an error message or throw an exception, or continue without executing this particular piece of functionality, whatever is necessary for your application
}
else {
//do something suitable here like display an error message or throw an exception, or continue without executing this particular piece of functionality, whatever is necessary for your application
}
See https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx for details and more examples.