have Dropdownlist which have languages how to reload page each time change selected item from dropdown ?
protected void DDLLanguages_SelectedIndexChanged(object sender, EventArgs e)
{
if (Request.RawUrl.Contains("Language") == false )
{
Response.Redirect(Request.RawUrl + "?Language=" + DDLLanguages.SelectedValue);
}
else
{
//i need to update the quesry string here
}
}
protected void DDLLanguages_SelectedIndexChanged(object sender, EventArgs e)
{
if (Request.RawUrl.Contains("Language") == false )
{
Response.Redirect(Request.RawUrl + "?Language=" + DDLLanguages.SelectedValue);
}
else
{
//i need to update the quesry string here
Response.Redirect(Request.Url.GetLeftPart(UriPartial.Path)+ "?Language=" + DDLLanguages.SelectedValue);
}
}
The accepted answer wipes out any existing query string values.
// parse url into UriBuilder //
var uri = new UriBuilder(Request.RawUrl);
// parse query part of url into a NameValueCollection //
var query = HttpUtility.ParseQueryString(uri.Query);
// update/create "Language" entry in the NameValueCollection //
query["Language"] = DDLLanguages.SelectedValue;
// put updated NameValueCollection back into uri querystring //
uri.Query = query.ToString();
// redirect page to updated uri //
Response.Redirect(uri.ToString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.