Disabling javascript generation using an ASP.NET control

On my website, I am using the standard ASP.NET control. I already got to the point of writing a custom management adapter to get rid of the rather sticky html output that is generated by the default management adapter.

One thing keeps me furious. Somehow ASP.NET generates additional javascript that I do not want and do not need menu controls, since I will not use any dynamic functions in the control. I replaced the management adapter, so no compatible HTML is created for it.

Has anyone understood how I can prevent ASP.NET from generating additional javascript for menu control?

+5
source share
5 answers

This problem occurred to me after upgrading to ASP.net 4.0 with vs 2010 installation. The fix is ​​to make the menu display as a table or disable the new CSS / javascript "features", which adds 4.0. The settings of the RenderingMode attribute of the menu in the "Table" fixed this problem for me, although I use the Menu Adapter to render the list control.

<asp:Menu ID="mnuStuff" runat="server" RenderingMode="Table">
    ...
</asp:Menu>

You can set this parameter at the site level of RenderingCompatibilityVersion to 3.5 in web.config:

<system.web> 
  <pages controlRenderingCompatibilityVersion="3.5"/> 
</system.web>

This will eliminate the rendering of inline javascript that asp injects into the page base.

+4
source

ASP.Net 4.0, ( System.Web.UI.WebControls.Menu) OnPreRender:

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

.

+2

script RegisterStartup script Menu PreRender script ( ) script.

, Reflector, .

, , :

static MenuHelper
{
    private static Type _rendererType = 
          typeof(Menu).Assembly.GetType(
              typeof(Menu).FullName + "+MenuRendererStandards"
              );

    public static void RemoveMenuScript(Menu menu)
    {
        string dummyScript = "<!-- Removed Menu Startup script -->";
        string key = "_registerMenu_" + menu.ClientID;
        ScriptManager.RegisterStartupScript(menu, _rendererType, key, dummyScript, false);
    }
}

, MenuHelper.RemoveMenuScript(menu) PreRender .

OP , . , .

+1
<script type="text/javascript">
    Sys.WebForms.Menu = "";
</script>

.

aspx

+1

2 .

jquery superfish, , . ASP.NET javascript, .

, , ASP.NET Enabled = false

:

new Sys.WebForms.Menu({ element: 'mysitemeun', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: **true** });

After tracking the code, when the parameter is disabled, there are still style changes in the Menu , but it will not add events to the MenuItem . And now the superfish animation is working .

if (!this.container.disabled) {
    Sys.WebForms.Menu._domHelper.addEvent(this.element, 'mouseover', Sys.WebForms.MenuItem._onmouseover);
    Sys.WebForms.Menu._domHelper.addEvent(this.element, 'mouseout', Sys.WebForms.MenuItem._onmouseout);
} 
0
source

All Articles