English 中文(简体)
How to get ASP.NET HyperLink control to encode ampersands in Text attribute?
原标题:

I use the following control to output a HTML link:

<asp:HyperLink ID="hlEditDetails" runat="server" CssClass="arrow-forward" Text="Edit Details &amp; Photo" />

However, when it does, the markup is generated as:

<a id="ctl00_hlEditDetails" class="arrow-forward" href="/EventName/EditDetails.aspx?ID=1">Edit Details & Photo</a>

The unescaped ampersand is causing an error on the XHTML validator. Is there a way to make the HyperLink control generate the text correctly without writing out the HTML ourselves? The reason we re using the control in the first place is because the URL is dynamic. It s not a huge problem, but very annoying to see validation fail due to .net inflexibility, when the control should be making things easier.

最佳回答

<asp:HyperLink ID="hlEditDetails" runat="server" CssClass="arrow-forward">Edit Details &amp; Photo</asp:Hyperlink>

works

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签