Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could have a class that you instantiate at the top of each page that will handle this for you. I've written an example below. ++Note that this is untested, I just threw it together to give you an idea++:</p> <pre><code>public class QueryStringState { private Dictionary&lt;string, string&gt; m_Params = new Dictionary&lt;string, string&gt;(); private System.Web.UI.Page m_Page; // ctor public QueryStringState(System.Web.UI.Page _page, params string[] _persistArgs) { m_Page = _page; foreach (string key in _page.Request.QueryString.Keys) { if (_persistArgs.Contains(key)) // are we persisting this? m_Params[key] = _page.Request.QueryString[key]; }; } // eo ctor // Resolve Url public string ResolveUrl(string _url) { // Resolve the URL appropriately string resolved = m_Page.ResolveUrl(_url); // Add our arguments on to the Url. This assumes that they have NOT been // put on the query string manually. Uri uri = new Uri(resolved); StringBuilder builder = new StringBuilder(uri.Query); if(uri.Query.Length &gt; 0) builder.Append("&amp;"); int counter = 0; foreach(KeyValuePair&lt;string, string&gt; pair in m_Params) { builder.AppendFormat("{0}={1}", pair.Key, pair.Value); ++counter; if(counter &lt; m_Params.Count) builder.Append("&amp;"); }; return(string.Concat(resolved, builder.ToString())); } }; </code></pre> <p>Let this class be a member of your page:</p> <pre><code>private QueryStringState m_QueryStringState = null; </code></pre> <p>And instantiate during initialisation, passing the names of any arguments you want to persist on the query string through pages:</p> <pre><code>m_QueryStringState = new QueryStringState(this, "param1", "param2"); </code></pre> <p>Then you must make sure that any URLs that leave the page are passed through the ResolveUrl() method of this class:</p> <pre><code>myObject.HyperLink = m_QueryStringState.ResolveUrl("~/index/mypage.aspx"); </code></pre> <p>As I stated, this is untested as I don't have the time right now to make sure it works exactly as intended but is to give you a general idea of how this might be solved. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload