Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 706379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:09:34+00:00 2026-05-14T04:09:34+00:00

I want to dynamically populate a link with the URI of the current request,

  • 0

I want to dynamically populate a link with the URI of the current request, but set one specific query string parameter. All other querystring paramaters (if there are any) should be left untouched. And I don’t know in advance what they might be.

Eg, imagine I want to build a link back to the current page, but with the querystring parameter “valueOfInterest” always set to be “wibble” (I’m doing this from the code-behind of an aspx page, .Net 3.5 in C# FWIW).

Eg, a request for either of these two:

/somepage.aspx
/somepage.aspx?valueOfInterest=sausages

would become:

/somepage.aspx?valueOfInterest=wibble

And most importantly (perhaps) a request for:

/somepage.aspx?boring=something
/somepage.aspx?boring=something&valueOfInterest=sausages

would preserve the boring params to become:

/somepage.aspx?boring=something&valueOfInterest=wibble

Caveats: I’d like to avoid string manipulation if there’s something more elegant in asp.net that is more robust. However if there isn’t something more elegant, so be it.

I’ve done (a little) homework:
I found a blog post which suggested copying the request into a local HttpRequest object, but that still has a read-only collection for the querystring params. I’ve also had a look at using a URI object, but that doesn’t seem to have a querystring

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:09:34+00:00Added an answer on May 14, 2026 at 4:09 am

    This will work as long as [1] you have a valid URL to begin with (which seems reasonable) [2] you make sure that your new value (‘sausages’) is properly escaped. There’s no parsing, the only string manipulation is to concatenate the parameters.

    Edit

    Here’s the C#:

        UriBuilder u = new UriBuilder(Request.Url);
        NameValueCollection nv = new NameValueCollection(Request.QueryString);
    
        /* A NameValueColllection automatically makes room if this is a new
           name. You don't have to check for NULL.
         */
        nv["valueOfInterest"] = "sausages";
    
        /* Appending to u.Query doesn't quite work, it
           overloaded to add an extra '?' each time. Have to 
           use StringBuilder instead.
        */
        StringBuilder newQuery = new StringBuilder();
        foreach (string k in nv.Keys)
            newQuery.AppendFormat("&{0}={1}", k, nv[k]);
    
        u.Query = newQuery.ToString();
        Response.Redirect(u.Uri.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to dynamically change content , by following code. localStorage.removeItem(some key); but current
I want to dynamically populate an un-ordered list in a Div section. But, I
I want to dynamically get the name of the current stored procedure inside itself
I want to dynamically query an object with System.Linq.Dynamic . var selectData = (from
I want to dynamically populate a form field from multiple other fields in the
I want to dynamically create and populate an excel spreadsheet with C++ builder 2009,
I want to create content type with multiple ListBox's which populate dynamically depending on
Want to populate dynamically combobox-listbox-drop-down using javascript. var table = document.createElement(table); var select =
i m using following code to populate dropdownlist dynamically... i want that value should
I want to populate a List dynamically and display the list when i hover

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.