Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu control generated js causes Sys undefined exception in Web Forms

I'm developing an ASP.NET 4 web application. When I put a Menu control into the web form, the menu causes the following code to generate just before the closing </form> tag:

 <script type='text/javascript'>
         new Sys.WebForms.Menu({ element: 'NavigationMenu', disappearAfter: 500, 
                orientation: 'horizontal', tabIndex: 0, disabled: false });

As long as I don't use URL Rewriting, the page compiles and loads properly. When I try to use URL Rewriting on the website, Visual Studio starts to throw "Sys is undefined" JavaScript exception.

However, this does not happen always. Most frequently it happens when I change somenting positioning-related in the CSS file, but sometimes the exceptions seems just arbitrary.

How can this be fixed?

like image 691
Jan Kratochvil Avatar asked Apr 18 '10 18:04

Jan Kratochvil


1 Answers

Settings the menu's RenderingMode attribute to "Table" fixed this problem for me even though I use a Menu Adapter to render the control with lists.

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

If you do not need to take advantage of asp 4.0 new css enhancements you can disable the injection of that new Sys.WebForms.Menu altogether with the following setting in the web.config.

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

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

like image 83
Tim Santeford Avatar answered Oct 02 '22 09:10

Tim Santeford