问题
I have got a BulletedList
with DisplayMode="HyperLink"
.
<asp:BulletedList runat="server" DisplayMode="HyperLink" ID="LevelsList"></asp:BulletedList>
I add items to the list with this code: LevelsList.Items.Add(new ListItem(curSubPage.PageName, curSubPage.shortURL));
The URL links contain Hebrew strings and they get encoded:
The markup the the asp.net generates is something like that:
<a href="%d7%91%d7%a0%d7%99%d7%99%d7%aa_%d7%90%d7%a4%d7%9c%d7%99%d7%a7%d7%a6%d7%99%d7%95%d7%aa_%d7%90%d7%99%d7%a0%d7%98%d7%a8%d7%a0%d7%98%d7%99%d7%95%d7%aa">בניית אפליקציות אינטרנטיות</a>
While the right markup should be:
<a href="בניית_אפליקציות_אינטרנטיות">בניית אפליקציות אינטרנטיות</a>
How do I fix it?
回答1:
From quick investigation, looks like ASP.NET is encoding it in its "low level" code, so no direct solution.
You can simply write your own Bulleted List using custom Repeater:
<asp:Repeater id="rptLevelsList" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<li><a href="<%# DataBinder.Eval(Container.DataItem, "Value") %>"><%# DataBinder.Eval(Container.DataItem, "Text") %></a></li>
</ItemTemplate>
</asp:Repeater>
And to bind it in code behind:
List<ListItem> links = new List<ListItem>();
links.Add(new ListItem("my page", "Somepage.aspx"));
links.Add(new ListItem("משהו בעברית", "http://www.כתובת_כלשהי_כאן.com"));
rptLevelsList.DataSource = links;
rptLevelsList.DataBind();
Note that from what I've seen, IE8 still does not support non english URL address - the above link is not clickable in that browser, while Chrome let you click it, but encode the URL to something else as well.
来源:https://stackoverflow.com/questions/4237361/how-to-make-asp-net-hyperlink-to-stop-encoding-the-urls