重写受保护的内部方法
我正在将一个 Web 应用程序重写为 ASP.Net 4.0,并包含一个菜单控件(自然地绑定到 SiteMap 文件)。虽然我喜欢新的 RenderingMode 属性,但我讨厌它自动在页面底部包含一些 JavaScript 来为菜单添加动画效果。
我更喜欢使用 jQuery 进行更好的控制,但事实证明关闭它非常困难。在一位重量级人物的帮助下,我已经发现 ASP.Net 4.0 菜单控件有一个内部 OnPreRender 方法:
internal void OnPreRender(EventArgs e, bool registerScript);
如何重写此方法以便我可以调用
base.OnPreRender(e, false);
:目前正在尝试,我从 Visual Studio 收到一条错误,指出“方法‘OnPreRender’没有重载需要 2 个参数”。
I'm rewriting a web application to ASP.Net 4.0 and have included a Menu control (bound to a SiteMap file, naturally). While I'm liking the new RenderingMode property, I'm hating the fact that it automagically includes some javascript at the bottom of your page to animate the menu.
My preference would be for greater control using jQuery, but switching that off is proving very difficult. With some help from a very heavy hitter, I've been walked through to the point where I've discovered that the ASP.Net 4.0 Menu control has an internal OnPreRender method:
internal void OnPreRender(EventArgs e, bool registerScript);
How do I override this method so that I can call:
base.OnPreRender(e, false);
When trying at the moment, I'm getting an error from Visual Studio saying that "No overload for method 'OnPreRender' takes 2 arguments".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够引用
受保护的内部
方法,因为它们是受保护
或内部
。如果该方法只是内部
,那么您可能会运气不好。查看 ASP.NET 4 菜单控件,它只有一个
OnPreRender
重写:因此您应该能够重写它。不确定 OnPreRender(EventArgs e, bool registerScript) 来自哪里(也许它是
内部
),但事实上基类没有(或者它无法访问)你的问题。You should be able to refer to
protected internal
methods as they areprotected
orinternal
. If the method is justinternal
you might be out of luck.Looking at ASP.NET 4 Menu control, it only has one
OnPreRender
override:So you should be able to override it. Not sure where
OnPreRender(EventArgs e, bool registerScript)
comes from (perhaps it'sinternal
), but the fact that the base class doesn't it(or it's inaccessible) is your problem.这不是一个直接的答案,但将任何 IHeirarchicalDataSource 的内容(例如站点地图文件)转储到任何数量的 jquery 菜单产品都可以咀嚼并制作的
中是非常简单的。
Not a direct answer, but its pretty trivial to dump the contents of any IHeirarchicalDataSource, such as a sitemap file, to a
<ul>
which any number of jquery menu products can chew and make purdy.