How to get data from url
I have a URL http: //localhost/TradeCredits/UnderWriter/EditQuote.aspx? QOT_ID = 1 I want to get the QOT_ID from the URL. Please suggest how to do this.
a source to share
You can use this line of code:
int id = Convert.ToInt32(Request.QueryString["QOT_ID"]);
Or this if you want to do the correct check:
int id;
if (int.TryParse(Request.QueryString["QOT_ID"], out id)) {
// Do something with the id variable
} else {
// Do something when QOT_ID cannot be parsed into an int
}
a source to share
If you have URL
, as you mentioned in your question, that cannot be connected to the current request, you can do it like this:
string url = "http://localhost/TradeCredits/UnderWriter/EditQuote.aspx?QOT_ID=1";
Uri uri = new Uri(url);
var parameters = HttpUtility.ParseQueryString(uri.Query);
var id = parameters["QOT_ID"];
and the id
variable contains your parameter value.
a source to share
The collection Request.QueryString
contains all the URL parameters - each of them can be accessed by name:
var val = Request.QueryString["QOT_ID"];
All return values are variables string
, so you may need to cast them to the appropriate type.
a source to share
Request.QueryString provides an array of string variables sent to the client
Request.QueryString["QOT_ID"]
See documentation
a source to share