November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
1. EPiServer.UriSupport.AddQueryString(CurrentPage.LinkURL, "querystringname", "querystringvalue")
For more query string parameters than one, use UriSupport.BuildQueryString(NameValueCollection).
2. Request.QueryString["querystringname"]
Hope it helps,
/Marten
I apologize for posting in such an old thread, but its the only one I've found through a couple of hours of searching that deals directly with my problem.
The Solution offered looks good, but i don't understand where the indicated piece of code goes? It seems to me like the statement is creating a link to the current page, with parameters.
I would love to se a more complete example
Furthermore, I would like to know if adding querystring (or any kind of) parameters to a link can be done through the link tool in the editor. I cant seem to be able to do this myself.
br
Jørgen
It's just an example, and not meant to be taken literally. Maybe a better example would be something like below. This code is executed code-behind when clicking a top menu quicksearch linkbutton called "SearchButton". It takes the content of a TextBox called QuickSearch and returns its value as a querystring to a designated search page (The "SearchPage" property).
protected void SearchButton_Click(object sender, EventArgs e)
{
string searchString = Server.UrlEncode(QuickSearch.Text.Trim());
PageReference searchPageRef = CurrentPage["SearchPage"] as PageReference;
if (string.IsNullOrEmpty(searchString) || searchPageRef == null)
return;
string searchPageUrl = UriSupport.AddQueryString( GetPage(searchPageRef).LinkURL, "q", searchString );
Response.Redirect(searchPageUrl, true);
}
If you still don't understand the concept, instead try to describe the problem you are facing.
Regarding your second question: I don't think there is a built-in functionality to include query strings in the editors link tool. You (i.e. The editorial person) may have to do this yourself in the HTML mode after you included the link, or build your own plugin that overrides the current link tool functionality, which may seem like a bit of overkill.
Hope it helps,
/Marten
I'm having a bit of a problem regarding the UriSupport.BuildQueryString method. I have this link to which I want to add three parameters. I do the following:
NameValueCollection myCol = new NameValueCollection();
myCol.Add("Comment", "false");
myCol.Add("EditMode", "true");
string redirect = CurrentPage.LinkURL + UriSupport.BuildQueryString(myCol);
When I click my link the page can't be displayed. I've altered the code above several times but with no luck. Does anybody have any solutions to my problem?
NameValueCollection myCol = new NameValueCollection();
myCol.Add("SkipCount", Count.ToString());
myCol.Add("SkipCount", Count.ToString());
myCol.Add("Year", DropDownYear.SelectedIndex.ToString());
myCol.Add("Month", DropDownMonth.SelectedIndex.ToString());
string pagelink = CurrentPage.LinkURL + UriSupport.BuildQueryString(myCol);
The reason you have to add the first parameter twice is that LinkURL already has query string parameters and the BuildQueryString method doesn't add a leading question mark. You will then end up with a url where the first SkipCount has been added to the parameter value of the previous parameter like this:
/template.aspx?id=3&epslanguage=enSkipCount=1&SkipCount=...
I'd recommend using the EPiServer.UrlBuilder to merge query strings
NameValueCollection myCol = new NameValueCollection();
myCol.Add("SkipCount", "1");
myCol.Add("Year", "2009");
UrlBuilder urlBuilder = new UrlBuilder(CurrentPage.LinkURL);
urlBuilder.MergeQueryCollection(myCol);
string pageLink = (string)urlBuilder;
Note that the explicit cast to a string of the urlBuilder is important.
I'm having some difficulties creating url's that includes querystring parameters. The project I'm working with uses friendly url's. So, my first question is: how do I build a correct link that includes querystring parameters?
My second question regards the action off grabbing the querystring parameters on the receiving page.
Thanks for your help.