我可以阻止.NET吃的ID?NET、ID

由网友(少女心英雄梦)分享简介:我对交易信息架构师和JavaScript开发的今天,但最近我已经得到回到后台再编码。而且,同时试图让一个HTML原型集成,并与我们的C#为基础的CMS的工作,我是来打击我们的程序员在HTML ID属性被任意地改写。NET表单元素。I'm an Information Architect and JavaScript...

我对交易信息架构师和JavaScript开发的今天,但最近我已经得到回到后台再编码。而且,同时试图让一个HTML原型集成,并与我们的C#为基础的CMS的工作,我是来打击我们的程序员在HTML ID属性被任意地改写。NET表单元素。

I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been getting back into back-end coding again. And, whilst trying to get an HTML prototype integrated and working with our C#-based CMS, I've come to blows with our programmers over the HTML ID attributes being arbitrarily rewritten by .NET for form elements.

我可以理解code-背后的推理.NET变化的标识,但事实上,你可以尝试开发例如,当不再使用的ID jQuery的增强型接口,会引起一些摩擦。我能做些什么来解决这个?

I can understand the code-behind reasoning for .NET changing IDs, but the fact you can no longer use IDs when trying to develop e.g. jQuery enhanced interfaces is causing some friction. What can I do to work around this?

我已经使用class属性,而不是尝试过,但是这是非常糟糕的,不是它的意思并没有得到解决。NET的这个问题有效地改变对飞渲染源。这也意味着,CSS是不太有用现在效率较低,以创建和维护。

I've tried using the class attribute instead, but that's really crappy, not what it's meant for and doesn't get around that problem of .NET effectively changing rendered source on the fly. It also means that CSS is less useful now and less efficient to create and maintain.

任何提示或建议大大AP preciated - 任何东西少一些不眠之夜......

Any tips or advice greatly appreciated--anything for a few less sleepless nights...

推荐答案

简短的答案是否定的,与web表单中的id总是可以根据元素嵌套改写。您可以访问通过ClientID属性的ID,所以你可以在页面/控制结束设置ID转换成变量在脚本中,然后把它们放进jQuery的。

The short answer is no, with webforms the id can always be rewritten depending on the nesting of the element. You can get access to the id through the ClientID property, so you could set the ids into variables in a script at the end of the page/control then put them into jQuery.

是这样的:

<asp:button id="ImAButton" runat="server">Click Me</asp:button>

<script type="text/javascript">
var buttonId = "<%=ImAButton.ClientId%>";
$("#"+buttonId).bind('click', function() { alert('hi); });
</script>

这是一个黑客,我知道,但它会奏效。 (我应该注意对联合国发起的,我使用的原型$度日ID的方法有)

It's a hack I know, but it will work. (I should note for the un-initiated, I'm using the Prototype $ get by id method there)

阅读全文

相关推荐

最新文章