I have the below code (parts removed for ease of reading)
<asp:Repeater ID="rptMenu" runat="server" OnItemDataBound="rptMenu_ItemDataBound">
<ItemTemplate>
<li>
<asp:HyperLink ID="hlCountries" runat="server" class="lang__option">
<asp:Image ID="imgGut" runat="server" />
<asp:Label ID="lblName" runat="server" Text=""></asp:Label>
</asp:HyperLink>
</li>
</ItemTemplate>
</asp:Repeater>
In my Item data bound (Again some code removed for ease of reading but can show if required)
protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//var nvc = HttpUtility.ParseQueryString(Request.Url.Query);
//nvc.Remove("c");
//string url = Request.Url.AbsolutePath + "?" + nvc.ToString();
hlCountries.NavigateUrl = string.Format("{0}/?c={1}",
System.Web.HttpContext.Current.Request.Url.AbsoluteUri, p.Id);
}
}
Page load i bind the data.
When the menu hyperlink is selected it adds a parameter to the URL load some data based on the query value passed in.
When the next item in the menu item is clicked it adds another parameter i.e.
Page load: getdata
Click first item getdata?c=1
Click second item getdata?c=1c=2
(notice how the c= is repeated) How could i avoid this from happening? I added the above commented out code but that didnt work?
You should use UriBuilder
when building Uri
instead of string concatenation
var builder = new UriBuilder(this.Request.Url);
var nvc = HttpUtility.ParseQueryString(this.Request.Url.Query);
nvc.["c"] = p.Id;
builder.Query = nvc.ToString();
hlCountries.NavigateUrl = builder.Uri.PathAndQuery;