Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
{
    string score = Request.QueryString["Score"];
    Label1.Text = score;
    int value = Convert.ToInt32(score);
    if (value >= 10)
    {
        Label2.Text = "Cheers ! your score is satisfactory to promote you for the next level. All the best for the Next Move.";
    }
    else
    {
        Label2.Text = "Sorry ! Your score is not satisfactory to promote you for the next level. You can again attempt this level after Seven Days.";
    }
}
protected void Button1_Click(object sender, EventArgs e)
{
    int level = Convert.ToInt32(Request.QueryString["level"]);
    Response.Redirect("Toplist.aspx?level=" + level);
}
}

Input string was not in correct format
Posted
v3
Comments
Shambhoo kumar 19-Apr-16 3:19am    
Again you asking same problem. why you are not checking your Score variable value.
Patrice T 19-Apr-16 3:20am    
Where is the error, What is the value of the string ?
Shambhoo kumar 19-Apr-16 3:20am    
Here is nothing wrong with your code please verify your score variable value. show your score variable value.
Jawad Ahmed Tanoli 19-Apr-16 3:21am    
which line is generating error?
int value = Convert.ToInt32(score); may be there have you try debug what is in score string?
Debug and find the exact line causing the exception. Most probably, it is due to bad formatted data or null value in string. Check it out.

1 solution

Stop using Convert methods to change between datatypes: particularly when you are converting from strings to numbers you need to use TryParse instead. Convert methods throw an exception when they fail, where TryParse returns a value which allows you to report problems instead of your app (and website) failing.
C#
string score = Request.QueryString["Score"];
Label1.Text = score;
int value;
if (!int32.TryParse(score, out value))
    {
    // Report problem, or log it.
    ...
    return;
    }
But the reason why it's failing is very likely to be in the code which directed you to this page: use the if above to show you what exactly the query string contains, and then look at what it should be - since you are generating the query string, you are probably doing something very, very wrong there.

As a side note: if you don't want users to progress until they have a sufficient score, then you need to look at using Cookies or the Session object instead of query strings. Otherwise I can progress immediately just by editing the query string in the URL at the top of my browser and pressing ENTER...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900