开发者

ClientIDMode How to hide ID in Html Source code generated in browser

I use .net 4 and c#.

I have a asp.net Page wit an HyperLink.

<asp:HyperLink ID="uxLink" ClientIDMode ="Static" runat="server"></asp:HyperLin开发者_JAVA技巧k>

In my code behind I use the HyperLink ID="uxLink" to change some properties.

In my browser the code generate is:

<a id="uxLink" href="/blog/5/test.aspx">Test link</a>

I would need omit the id from the source code generated in the browser so it should look:

<a href="/blog/5/test.aspx">Test link</a>

I tried to play with ClientIdMode but with no succe... Any idea how to do it? Thanks


If you remove ClientIDMode ="Static", the framework will generate a "big unique" ID for the element, but still, there will be an ID.

Having an ID is fundamental if you want to handle the elements in client-side script. The IDs should not be removed.

If you don't want them, just don't use ASP.NET components, use the <a> tag itself.

Update

By the way, supposedly there's a way to do what you want in ASP.NET 4. It's described here: http://www.codeproject.com/Tips/208323/Disable-ClientID-for-any-control-on-ASP-NET-Page?display=Print

I haven't tried it, I'm just pointing you into a direction. You should be aware of the implications of not having a ClientID, though. Specially for Postback controls. Read the article.


The easiest solution is to change the ID propriety for the control in code behind before rendering the page to NULL.

in my example:

myLink.ID = null;

This would generate no ID at the Browser resulting in:

<a href="/blog/5/test.aspx">Test link</a>

I find this useful trick on this website: http://www.dotnetperls.com/remove-id

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜