Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a simple way to remove the "ct100" prefix from a .NET user control?

Long story short, dozens of pages use no master page. For a new module I created a master page with a menu control (menu control exists already) so I can get the same look across the six or so pages I'm creating now. Since the content page uses the master page, the Menu control has its name changed to ct100_Menu1 instead of just Menu1. Wouldn't be an issue except someone decided to use the exact name of the control for the CSS that styles the menu, by its exact ID (e.g. CSS is Menu1 a { /* stuff */ }). So the menu won't render properly because I'm using a Master Page and not just copying the code.

I cannot change the CSS code in the menu file as it could break something, so is there any way that I can change the control to not display that pesky ct100 without having to add any tools or mess with creating my own custom control (as I can't replace the Menu.ascx control, although I might be able to modify it to add CSS classes) or is my only choice to either not use a master page or copy the menu CSS into another file and set it properly?

Feel kind of stuck between a rock and a hard place because the code was deliberately written so you cannot use Master Pages and nobody ever went back to change it.

like image 439
Wayne Molina Avatar asked Dec 17 '22 10:12

Wayne Molina


2 Answers

You should set the ClientIdMode to Static. Here's more information from MSDN. Note: This is .NET 4.0 only.

In earlier versions, I would recommend styling off of classes as you can't really control what the name will be everywhere that you use it (as you found out).

like image 77
scottheckel Avatar answered Dec 18 '22 23:12

scottheckel


If you are on ASP.net 4.0, you can set the ClientID property of the controls.

Otherwise, you're in for a world of hurt as in: Custom Control, ASP.net Literals or JavaScript to change the IDs.

like image 38
Michael Stum Avatar answered Dec 18 '22 23:12

Michael Stum