开发者

Need workaround for .Net Master Page Name Mangling

开发者 https://www.devze.com 2022-12-11 17:12 出处:网络
I\'m evaluating converting an old frameset based asp.net website to use master pages.The only thing holding me back is the huge amount of work it will take to update every page to deal with name mangl

I'm evaluating converting an old frameset based asp.net website to use master pages. 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.

Is there a way for me to tell ASP.Net that for a particular content area that I don't want mangling to occur. Leave it to me deal with name conflicts.

Note

开发者_开发问答

I'm aware .Net 4.0 has a solution for this as detailed here. I want a solution that doesn't involve waiting, needs to be .Net 3.5.

Update

Any suggestions for opensource alternatives to masterpages that will get me by until .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"". Otherwise, .NET 4.0 is the first time that you are given a consistent, supported mechanism to make this change.

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. You can access the generated ID using the ClientID property. 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.

0

精彩评论

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