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

Last Reply 5 months ago By pandeyism

Posted 5 months 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"]);

 

You are viewing reply posted by: pandeyism 5 months ago.
Posted 5 months 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"]);
}