Retrieving QueryString Error: Input string was not in a correct format

Last Reply 14 days ago By pandeyism

Posted 14 days ago

Hello Sir,

Getting this error: System.FormatException: Input string was not in a correct format.

Using below code in emp.aspx to pass Id from gridview.

string url = "~/abc.aspx?ID=" + role + "&Id=" + Server.UrlEncode(Id.ToString());

on page load of abc.aspx webpage using below line of code

 Id = Convert.ToInt32(Request.QueryString["Id"]);

 

Posted 14 days ago

Hey democloud,

Please provided different parameter name. you have pass same name for parameters so that value come with comma and throw error.

Code

CS.aspx

protected void Page_Load(object sender, EventArgs e)
{
    string url = "~/abc.aspx?ID=" + 1 + "&eId=" + Server.UrlEncode(2.ToString());
    Response.Redirect(url);
}

abc.aspx

protected void Page_Load(object sender, EventArgs e)
{
    int Id = Convert.ToInt32(Request.QueryString["eId"]);
}