How to disable a Menu control from a style in javascript?

I use Visual Studio 2010 and ASP.NET 4.0 to render the menu control as an HTML list, so I can style it with CSS. Here is the code I use below

<asp:Menu ID="navlist" runat="server" Orientation="Horizontal"
SkipLinkText="" ClientIDMode="Static" DataSourceID="MenuSource" 
MaximumDynamicDisplayLevels="0" IncludeStyleBlock="False" 
StaticDisplayLevels="2">
</asp:Menu>

This creates the following HTML

<!-- URL shortened -->
<script src="/WebResource.axd?...t=634066906994188146"type="text/javascript"></script>

<div id="navlist">
    <ul>
        <li><a href="link1.html">Link 1</a></li>
        <li><a href="link2.html">Link 2</a></li>
    </ul>
</div>

At first glance, it looks like what I wanted. However, if I open WebResource.axd, there is a whole bunch of javascript code related to the menu. Part of this code applies its own inline styles to it. Using FireBug, I can view the HTML markup after running javascript and looks something like this:

<div id="navlist" style="float: left;">
    <ul class="level1 static" tabindex="0" style="position: relative; width: auto; float: left;" role="menubar">
        <li role="menuitem" class="static" style="position: relative; float: left;">
            <a href="link1.html" class="level2 static" tabindex="-1">Link 1</a>
        </li><li role="menuitem" class="static" style="position: relative; float: left;">
            <a href="link2.html" class="level2 static" tabindex="-1">Link 2</a></li>
    </ul>
</div>

These inline styles ultimately affect the layout of my page. I do not need any of the scripts in WebResource.axd. How can I prevent this script from appearing in the final page layout?

+3
6

Menu. , , CSS-.

+2

, IncludeStyleBlock

"true"

<asp:Menu IncludeStyleBlock="False" />
+8

css ! important

+5

( System.Web.UI.WebControls.Menu) OnPreRender:

public class MyCustomMenu : System.Web.UI.WebControls.Menu
{
    protected override void OnPreRender(EventArgs e)
    {
        // Don't call base OnPreRender
        //base.OnPreRender(e);
    }
}

.

+3

, jQuery. , , css.

, li, a, ul divs:

$("#navlist li,#navlist li a,#navlist ul,#navlist div").removeAttr('style');

-, , :

$("#from-this-element").removeClass(.remove-me).addClass('.new-class');

, script .

0

asp:menu , , ul, li a, css- .

Imports Microsoft.VisualBasic
Namespace MCO

Public Class MyCustomMenu
    Inherits Menu

        Protected Overrides Sub OnPreRender(e As EventArgs)
            ' don't use this:
            ' MyBase.OnPreRender(e)

            ' but leaving this blank produces NO rendered menu
        End Sub
    End Class
End Namespace

jQuery:

$("#navlist li,#navlist li a,#navlist ul,#navlist div").removeAttr('style');

.net webresource.net, , jQuery . , . :(

0

Source: https://habr.com/ru/post/1750787/


All Articles