This error occurs because of conversion. The value is non-numeric or blank string.
Check this similar question with answer to solve your issue.
Conversion from string to int[
^]
Few suggestions:
Don't put massive code in
Page_Load()
, create a function/sub procedure for that & call it in
Page_Load()
like below.
protected void Page_Load(object sender, EventArgs e)
{
InitRangeValidations();
}
protected void InitRangeValidations()
{
RangeValidatorLYTNFUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) - Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);
RangeValidatorLYTNFUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) + Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);
}
And try to simplify your code, the below one is simpler than yours, agree? It's more readable one. I could simplify even more than this(like reducing 2 or 3 lines).
protected void InitRangeValidations()
{
int itxtVal = Convert.ToInt32(TextBoxLYTNFUG.Text);
int iMinVal = (itxtVal - itxtVal * 20 / 100);
int iMaxVal = (itxtVal + itxtVal * 20 / 100);
RangeValidatorLYTNFUG.MinimumValue = iMinVal.ToString();
RangeValidatorLYTNFUG.MaximumValue = iMaxVal.ToString();
}
I know you're posting questions here with clear details regularly, keep doing this. Here suggestions for you to optimize your code.
Some practices to write better C#/.NET code[
^]
Some Best Practices for C# Application Development (Explained)[
^]