简体   繁体   English

需要解决.Net母版页名称管理问题

[英]Need workaround for .Net Master Page Name Mangling

I'm evaluating converting an old frameset based asp.net website to use master pages. 我正在评估将基于旧框架集的asp.net网站转换为使用母版页。 The only thing holding me back is the huge amount of work it will take to update every page to deal with name mangling. 阻碍我的唯一事情是更新每一页以处理名称错误所需的大量工作。 Most of my problems are with javascript referencing hardcoded Id's. 我的大部分问题都是javascript引用硬编码的Id。

Is there a way for me to tell ASP.Net that for a particular content area that I don't want mangling to occur. 有没有办法让我告诉ASP.Net,对于特定的内容区域我不希望发生错误。 Leave it to me deal with name conflicts. 留给我处理名称冲突。

Note 注意

I'm aware .Net 4.0 has a solution for this as detailed here . 我知道.Net 4.0有一个解决方案, 详见此处 I want a solution that doesn't involve waiting, needs to be .Net 3.5. 我想要一个不涉及等待的解决方案,需要.Net 3.5。

Update 更新

Any suggestions for opensource alternatives to masterpages that will get me by until .Net 4.0? 有关开源替代主页的任何建议会让我直到.Net 4.0? Or how about a hack job solution to work around the mangling. 或者如何解决破解工作的黑客工作解决方案。 Thanks 谢谢

The only "supported" way to do this is to NOT use elements that are defined as "runat="server"". 唯一“支持”的方法是不使用定义为“runat =”server“”的元素。 Otherwise, .NET 4.0 is the first time that you are given a consistent, supported mechanism to make this change. 否则,.NET 4.0是第一次为您提供一致的,受支持的机制来进行此更改。

You might be able to get around this via other means, but nothing that is going to be easy/quick to implement. 您可以通过其他方式绕过这个,但没有什么是容易/快速实现的。

One way to do this is with some server-generated JavaScript that associates the generated ID with a more friendly name. 一种方法是使用一些服务器生成的JavaScript将生成的ID与更友好的名称相关联。 You can access the generated ID using the ClientID property. 您可以使用ClientID属性访问生成的ID。 For example: 例如:

<asp:Label runat="server" ID="myInfo" Text="Initial text" />    
<script type="text/javascript">
  function RegObj(clientId, anId) {
    eval('window.' + clientId + ' = document.getElementById(anId)');
  }
  RegObj('mytext', '<%= myInfo.ClientID %>');
  mytext.innerHTML = 'my text';
</script>

This reported ID includes any mangling done by Master Pages, nested controls, etc. 此报告的ID包括由母版页,嵌套控件等完成的任何修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM