开发者

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 fo开发者_StackOverflow中文版llowing 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?


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.


RouteTable.Routes.Ignore("{resource}.axd");


I know the question is old, but this may help some pour soul ... ;-)

I managed to fix this by moving at the end of the page the jquery related scripts. I haven't spent to much time to investigate why, but it looks like it is clearly a javascript naming conflict between the javascript-resource-file (WebResource/*.axd) and jquery (1.10 at the time of writing this).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜