Need workaround for .Net Master Page Name Mangling

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

Answers:

Answer

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.

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.